views:

162

answers:

1

I'm using the 'modules' front controller resource for the project setup. What's the best approach to render site-wide elements, like navigation?

  • Add the action which renders the element to the end of the action stack each request?
    • is it OK to render these elements through controller actions?
  • Create a plugin which renders the element?
    • Could I use module specific plugins?
  • are there other possible ways to do this?
+3  A: 

I think the action stack should be avoided. See this article for why.

The plugin method could work or you can create ViewHelpers which you call from you layout script. I like the ViewHelpers method because it keeps everything very clear. You know that when you echo out $this->mainNaviation() that there is a ViewHelper called MainNavigation.

smack0007
Thx for thr article. The view helper does idd seem a good idea. One more question: how do you call namespaced viewhelpers? $this->module_mainNav() ?
Nicky De Maeyer
You can't really call ViewHeleprs from different namespaces. You can set which ViewHelpers will be called by setting the helperPath. See http://framework.zend.com/manual/en/zend.view.helpers.html#zend.view.helpers.paths. You can use that to call one ViewHelper in module A, B, C but a more specific one in module D.
smack0007
Then it becomes quite useless if I can't use it from within other components? If i have a MainNav inside a menu module, i can only display the navigation when inside the menu module.... or I should inspect my whole module directory to manually add all helper directories :s
Nicky De Maeyer
I dont't think I explained that very well. You can create a hierarchy such that there is a default mainNav() ViewHelper and a module specific mainNav() ViewHelper. From your layout you can just call $this->mainNav(). In your modules, you can set it up so that the module ViewHelpers get called instead of the normal ViewHelpers. This explained in the link I posted. They call it stacking.
smack0007