I am just wondering what would be the best way, to use Zend_Navigation in Zend Framework2. At the moment i am trying to a add a Config for a Header and a Footer Menu. Both Menus should be populated automatically. Though, i have run into a lot of Problems:
a) The best place for the Default Menu should be hopefully the Application-Module
b) I added the following to the root of module.config.php:
'view_helpers' => array(
'helper_map' => array(
'navigation' => 'Application\View\Helper\Navigation'
),
),
My Navigation.php is located in ./module/Application/src/Application/View/Helper/Navigation.php
and contains:
class Navigation extends AbstractContainer {
public function __construct($menu = null) {
var_dump($menu);
}
}
I know that the Class may be wrong. But at the Moment i did not get ZF2 to even load the Class. What is wrong ?
Assuming you're using beta5 - you're just configuring your viewhelper wrong. See this post on how to do it correctly.
On how to use navigation: I'd create a service in the servicemanager called
navigation
and put my navigation into a new config-key:(Not sure about the navigation class names. Haven't had a look on them.)
This does three things:
navigation
pointing to the actual instance if zend's navigationnavigation
containing the navigation configuration. Other modules can add custom navigation here without changing anything in your setup.For example in your controllers you code fetch the navigation instance by calling
while in your view helper has access to the navigation by it's constructor:
Other modules can add entries to your navigation by writing into the same key:
Where you put the initial logic (e.g. setting up the services/view helpers) is up to you. I prefer writing a own module for this which can be disabled with a single line of code (resulting in the navigation not being present anymore). But the default module is probably a good place as well. Ultimately you could create your own factory-classes for the navigation and view helper instead of mixing the configuration with your code.
Disclaimer: Code's just a draft - not tested.