Routers inside CLI

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Routers inside CLI

Oscar Fanelli
Hi guys, i'm trying to use some view templates inside the Zend Console (for sending my emails) and I found a problem: I can't read the routers…

When inside the template is called url('home') it throw this error
An exception has been thrown during the rendering of a template ("Route with name "home" not found") in "/path/to/the/view/file.phtml".


So… how can I read the routers that are inside my module.config.php, from the CLI ?


Thanks

Reply | Threaded
Open this post in threaded view
|

Re: Routers inside CLI

AndrejAndb
from cli http router located at like
$this->getServiceManager()->get('http_router')

$this->getServiceManager()->get('router') - its CLI router, and its
used URL helper

you may push link to template from controller like:
$http_router = $this->getServiceManager()->get('http_router')->setRequestUri(new
\Zend\Uri\Http('http://sample.com/'));
$viewModel['url'] = $http_router->assemble(array(...),
array('force_canonical' => true, 'name' => '....'));

setRequestUri required for force_canonical in assemble

or you may create custom URL helper, and use http_router from him. Or
setting Http_router to standart URL helper. or more...

PS. and i think in framework need realise this custom URL Helper, for
using from CLI :)



2012/9/15 Oscar Fanelli <[hidden email]>:

> Hi guys, i'm trying to use some view templates inside the Zend Console (for sending my emails) and I found a problem: I can't read the routers…
>
> When inside the template is called url('home') it throw this error
> An exception has been thrown during the rendering of a template ("Route with name "home" not found") in "/path/to/the/view/file.phtml".
>
>
> So… how can I read the routers that are inside my module.config.php, from the CLI ?
>
>
> Thanks
>
Reply | Threaded
Open this post in threaded view
|

Re: Routers inside CLI

Jurian Sluiman
In reply to this post by Oscar Fanelli
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Routers inside CLI

Oscar Fanelli
@Jurians, how can i use that fix? Can you provide me a complete example?

@Andrej are you suggesting me to put each of my http routes inside the cli router manually? so, with a foreach? i do not understand well what you was talking about

Il giorno 15/set/2012, alle ore 20:57, Jurian Sluiman <[hidden email]> ha scritto:

2012/9/15 Oscar Fanelli <[hidden email]>
Hi guys, i'm trying to use some view templates inside the Zend Console (for sending my emails) and I found a problem: I can't read the routers…

When inside the template is called url('home') it throw this error
An exception has been thrown during the rendering of a template ("Route with name "home" not found") in "/path/to/the/view/file.phtml".


So… how can I read the routers that are inside my module.config.php, from the CLI ?

This is a known problem. Since the introduction of the console, the application knows either the HTTP router *or* the CLI router. You fetch "router" from the service manager and you get one back based on your own environment.

Due to this single factory, it is currently not possible to fetch routes from the HTTP router inside a CLI environment (like you wish now).

There is a suggested fix, to have two service manager keys, "HttpRouter" and "CliRouter" for example. When you fetch the "router", you automatically fetch one of those based on your current environment. The plugins like the url helper get the HttpRouter injected, so they always work in whatever environment you are.

I am not sure this issue is already filed in Jira, but I have spoken with others about this recently on IRC.
-- 
Jurian Sluiman

Reply | Threaded
Open this post in threaded view
|

Re: Routers inside CLI

Oscar Fanelli
In reply to this post by AndrejAndb
@Andrej can you provide me a full example of an alternative url helper that do this for me? thanks


Il giorno 15/set/2012, alle ore 18:44, Андрей Баранов <[hidden email]> ha scritto:

from cli http router located at like
$this->getServiceManager()->get('http_router')

$this->getServiceManager()->get('router') - its CLI router, and its
used URL helper

you may push link to template from controller like:
$http_router = $this->getServiceManager()->get('http_router')->setRequestUri(new
\Zend\Uri\Http('http://sample.com/'));
$viewModel['url'] = $http_router->assemble(array(...),
array('force_canonical' => true, 'name' => '....'));

setRequestUri required for force_canonical in assemble

or you may create custom URL helper, and use http_router from him. Or
setting Http_router to standart URL helper. or more...

PS. and i think in framework need realise this custom URL Helper, for
using from CLI :)



2012/9/15 Oscar Fanelli <[hidden email]>:
Hi guys, i'm trying to use some view templates inside the Zend Console (for sending my emails) and I found a problem: I can't read the routers…

When inside the template is called url('home') it throw this error
An exception has been thrown during the rendering of a template ("Route with name "home" not found") in "/path/to/the/view/file.phtml".


So… how can I read the routers that are inside my module.config.php, from the CLI ?


Thanks


Reply | Threaded
Open this post in threaded view
|

Re: Routers inside CLI

AndrejAndb
@Oscar for example: https://gist.github.com/3731809

2012/9/16 Oscar Fanelli <[hidden email]>:

> @Andrej can you provide me a full example of an alternative url helper that
> do this for me? thanks
>
>
> Il giorno 15/set/2012, alle ore 18:44, Андрей Баранов
> <[hidden email]> ha scritto:
>
> from cli http router located at like
> $this->getServiceManager()->get('http_router')
>
> $this->getServiceManager()->get('router') - its CLI router, and its
> used URL helper
>
> you may push link to template from controller like:
> $http_router =
> $this->getServiceManager()->get('http_router')->setRequestUri(new
> \Zend\Uri\Http('http://sample.com/'));
> $viewModel['url'] = $http_router->assemble(array(...),
> array('force_canonical' => true, 'name' => '....'));
>
> setRequestUri required for force_canonical in assemble
>
> or you may create custom URL helper, and use http_router from him. Or
> setting Http_router to standart URL helper. or more...
>
> PS. and i think in framework need realise this custom URL Helper, for
> using from CLI :)
>
>
>
> 2012/9/15 Oscar Fanelli <[hidden email]>:
>
> Hi guys, i'm trying to use some view templates inside the Zend Console (for
> sending my emails) and I found a problem: I can't read the routers...
>
> When inside the template is called url('home') it throw this error
> An exception has been thrown during the rendering of a template ("Route with
> name "home" not found") in "/path/to/the/view/file.phtml".
>
>
> So... how can I read the routers that are inside my module.config.php, from
> the CLI ?
>
>
> Thanks
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Routers inside CLI

Jurian Sluiman
In reply to this post by Oscar Fanelli
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Routers inside CLI

Oscar Fanelli
Thanks to all, very good job. Now i'm using the andrej solution :)

Il giorno 18/set/2012, alle ore 21:19, Jurian Sluiman <[hidden email]> ha scritto:

2012/9/15 Oscar Fanelli <[hidden email]>
@Jurians, how can i use that fix? Can you provide me a complete example?

I have created a PR to address this issue. When this is merged, you should be able to create urls within your cli environment.

You can check the status here: https://github.com/zendframework/zf2/pull/2384
--
Jurian Sluiman

Reply | Threaded
Open this post in threaded view
|

Re: Routers inside CLI

David Muir-2
In reply to this post by AndrejAndb
Technical issues aside, Shouldn't the Url helper always pull the http router? It doesn't make sense to pull the cli router when producing a URL, does it?

Cheers,
David

On 16/09/2012, at 2:44 AM, Андрей Баранов <[hidden email]> wrote:

> from cli http router located at like
> $this->getServiceManager()->get('http_router')
>
> $this->getServiceManager()->get('router') - its CLI router, and its
> used URL helper
>
> you may push link to template from controller like:
> $http_router = $this->getServiceManager()->get('http_router')->setRequestUri(new
> \Zend\Uri\Http('http://sample.com/'));
> $viewModel['url'] = $http_router->assemble(array(...),
> array('force_canonical' => true, 'name' => '....'));
>
> setRequestUri required for force_canonical in assemble
>
> or you may create custom URL helper, and use http_router from him. Or
> setting Http_router to standart URL helper. or more...
>
> PS. and i think in framework need realise this custom URL Helper, for
> using from CLI :)
>
>
>
> 2012/9/15 Oscar Fanelli <[hidden email]>:
>> Hi guys, i'm trying to use some view templates inside the Zend Console (for sending my emails) and I found a problem: I can't read the routers…
>>
>> When inside the template is called url('home') it throw this error
>> An exception has been thrown during the rendering of a template ("Route with name "home" not found") in "/path/to/the/view/file.phtml".
>>
>>
>> So… how can I read the routers that are inside my module.config.php, from the CLI ?
>>
>>
>> Thanks
>>
Reply | Threaded
Open this post in threaded view
|

Re: Routers inside CLI

AndrejAndb
> Shouldn't the Url helper always pull the http router?
I think yes. Url Helper must be reproduce URI string, but with CLI
router does not make sense.

2012/9/19 David Muir <[hidden email]>:

> Technical issues aside, Shouldn't the Url helper always pull the http router? It doesn't make sense to pull the cli router when producing a URL, does it?
>
> Cheers,
> David
>
> On 16/09/2012, at 2:44 AM, Андрей Баранов <[hidden email]> wrote:
>
>> from cli http router located at like
>> $this->getServiceManager()->get('http_router')
>>
>> $this->getServiceManager()->get('router') - its CLI router, and its
>> used URL helper
>>
>> you may push link to template from controller like:
>> $http_router = $this->getServiceManager()->get('http_router')->setRequestUri(new
>> \Zend\Uri\Http('http://sample.com/'));
>> $viewModel['url'] = $http_router->assemble(array(...),
>> array('force_canonical' => true, 'name' => '....'));
>>
>> setRequestUri required for force_canonical in assemble
>>
>> or you may create custom URL helper, and use http_router from him. Or
>> setting Http_router to standart URL helper. or more...
>>
>> PS. and i think in framework need realise this custom URL Helper, for
>> using from CLI :)
>>
>>
>>
>> 2012/9/15 Oscar Fanelli <[hidden email]>:
>>> Hi guys, i'm trying to use some view templates inside the Zend Console (for sending my emails) and I found a problem: I can't read the routers...
>>>
>>> When inside the template is called url('home') it throw this error
>>> An exception has been thrown during the rendering of a template ("Route with name "home" not found") in "/path/to/the/view/file.phtml".
>>>
>>>
>>> So... how can I read the routers that are inside my module.config.php, from the CLI ?
>>>
>>>
>>> Thanks
>>>
Reply | Threaded
Open this post in threaded view
|

Re: Routers inside CLI

Jurian Sluiman
In reply to this post by David Muir-2
CONTENTS DELETED
The author has deleted this message.