Hi Jonathan,

2012/5/26 Jonathan Maron <[email protected]>

> Hello Roman
>
> I have asked myself the same question: How can I pass basic, standard
> variables to the View that should be available on every section of the
> module. I your case, you just want the names of controller and action
> in the View. I also want some more standard variables (locale, uri
> etc).
>
> I have come up with a solution that involves a custom
> \Zend\Mvc\Controller\ActionController that is then used by the
> Controllers.
>
> Please take a look at this solution:
>
> https://gist.github.com/2792133
>
> I am looking at your solution right now.
>
> What are the advantages of these two approaches?
>
> Jonathan Maron


In your approach you always need to use $this->view for returning a view
object. If you use another module from someone else, s/he probably isn't
using your own action controller, so there you don't have those variables.

For very simple parameter injection I'd go with the Module.php listener
approach. It's independent from whatever you do with your controllers and
thus much safer. Keep in mind this can go wrong for perhaps CLI requests or
http requests which do not use the PhpRenderer but instead return a JSON
response.

If you have more complex variables required in your view script, you could
write a view helper for that. Your uri parameters is an excellent example
for that imho.
-- 
Jurian Sluiman

Reply via email to