Question

I'm trying to render only a part of the menu configuration in my ZF2 application. I cant find anything about how to do this.

My configuration is:

array(
    'default' => array(
        'dashbord' => array(
            'label' => 'Dashbord',
            'route' => 'nav',
        ),
        'settings' => array(
            'label' => 'Settings',
            'route' => 'nav',
            'pages' => array(
            'Api Settings' => array(
                'label'=>'NAV_API_SETTINGS',
                'route'=>'nav'
             ),
        ),
    ),
    'NEW' =>array(
        'dashboard' => array(
            'label' => 'dashboard',
            'route' => 'nav',
        )
    )
);

So i have the subsets default and NEW. I need to render only the subset "NEW" of my menu. How do i do this?

Was it helpful?

Solution

in some Module.php or where you create your navigation, assuming your given config is stored in $config and you have access to the ServiceManager in $serviceManager

$navigation = new \Zend\Navigation\Navigation($config['NEW']);
$serviceManager->setService('new_navigation', $navigation);

in a view/layout

<?php echo $this->navigation()->menu('new_navigation') ?>

PS: in any Module.php you can get the serviceManager like this:

public function onBootstrap(\Zend\EventManager\EventInterface $e)
{
    $application = $e->getApplication();
    $serviceManager = $application->getServiceManager();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top