Sorry I missed your last message ...

My question is : now that I have a proper way to forward my environment id
in each requests once it has been selected, I'd like to know where I can
globally manage this parameter :
 - Get the id from url
 - Retrieve the environment in database
 - Store the « selected environment » somewhere where all my controllers
can say : « ok there is a selected environment, so i have to filter all my
results with this environment ».

I know how I can do these treatments, but not yet where I have to implement
them (in the boostrap of the module ? Attaching it to a MVC event ?), and
where to store the selected environment (in the service manager ?).

Thanks,
Emmanuel

2014-07-26 7:15 GMT+02:00 Alejandro Celaya <[email protected]>:

> I'm not sure if I understood you. You mean how to deal with database
> persistence in Zend framework 2?
>
> --
> Alejandro Celaya Alastrué
> http://www.alejandrocelaya.com
> El 26/07/2014 01:28, "Emmanuel Bouton" <[email protected]> escribió:
>
> Wow it seems exactly what I need thanks a lot :)
>>
>> Another thing, how would you manage globally the treatment of the selected
>> environment (retrieving the environment in the database) ?
>> And how should I store the environment so that I could use it when needed
>> ?
>>
>>
>> 2014-07-25 22:18 GMT+02:00 Alejandro Celaya <[email protected]>:
>>
>> > Hi!
>> >
>> > You could define an optional parameter in your route and then use the
>> Url
>> > view helper to inherit that value.
>> > When the param is not set in your current route it will use the default
>> > value (or no value), otherwise it will use the current value.
>> >
>> > For example, If you have defined this routes:
>> >
>> > 'home' => [
>> >     'type' => 'Zend\Mvc\Router\Http\Segment',
>> >     'options' => [
>> >         'route'    => '/[:env]',
>> >         'defaults' => [
>> >             'controller' => 'Application\Controller\Index',
>> >             'action'     => 'index'
>> >         ],
>> >     ],
>> > ],
>> >
>> > 'another-route' => array(
>> >     'type' => 'Zend\Mvc\Router\Http\Segment',
>> >     'options' => array(
>> >         'route'    => '/foo/bar/[:env]',
>> >         'defaults' => array(
>> >             'controller' => 'Application\Controller\Foo',
>> >             'action'     => 'bar'
>> >         ),
>> >     ),
>> > ),
>> >
>> >
>> > When you are in www.mydomain.com/, if you use the URL view helper like
>> > this, $this->url('another-route', [], true), it will produce the route
>> > '/foo/bar/'
>> > Otherwise, if you are in www.mydomain.com/another-env, the same
>> previous
>> > usage of the URL view helper will produce the route
>> '/foo/bar/another-env'
>> > This is because of the last boolean parameter of the URL view helper,
>> > which defaults to false. In any place where you don't want the env
>> > parameter to be inherited, just don't use the inheritance and set it
>> > yourself like this $this->url('another-royute', ['env' =>
>> 'another-one'])
>> >
>> > You could define constraints for your env if you need it, and also
>> define
>> > a default value.
>> >
>> > Best regards.
>> >
>> >
>> >
>> > 2014-07-25 21:51 GMT+02:00 Emmanuel Bouton <[email protected]>:
>> >
>> > Hello,
>> >>
>> >> I'm working on a web admin that manages a list of servers.
>> >> In the header of all the pages there's a select box for the servers
>> >> environments.
>> >>
>> >> When no environment is selected, all the pages concerns all the
>> servers.
>> >> When an environment is selected, all the pages concerns only the
>> server of
>> >> this specific environment.
>> >>
>> >> The easy way to manage the current environment in all my controllers
>> would
>> >> be to store it in the session. But I'd rather send it on each request.
>> >> That
>> >> would allow to work on multiple environments in several tabs of the
>> same
>> >> browser.
>> >>
>> >> How would you do that ?
>> >> Is there a proper way to change all urls in views to add the
>> environment
>> >> id
>> >> when it has been selected ? maybe in the routes ?
>> >>
>> >> Thanks,
>> >> Emmanuel
>> >>
>> >
>> >
>> >
>> > --
>> > Alejandro Celaya Alastrué
>> > http://www.alejandrocelaya.com
>> >
>>
>

Reply via email to