Reputation: 31610
Using zf2 I have a view helper that looks like this:
class Navbar extends AbstractHelper implements ServiceLocatorAwareInterface {
public function setServiceLocator(ServiceLocatorInterface $serviceLocator) {
$this->serviceLocator = $serviceLocator;
return $this;
}
public function getServiceLocator() {
return $this->serviceLocator;
}
public function __invoke($container) {
$partial = array('partial/subNav.phtml','thisMeansNothing');
//github.com/zendframework/zf2/issues/3457
$navigation = $this->getServiceLocator()->get('navigation');
$navigation($container)->menu()->setPartial($partial);
return $navigation->menu()->render();
}
}
This works really well for me because I can just do echo $this->navbar('navigation');
in my views.
In my module's module.config.php I have this:
...
'navigation' => array(
'default' => array(
array(
'label' => 'eeee',
'route' => 'link',
),
array(
'label' => 'sdlfkj',
'route' => 'link',
),
array(
'label' => 'sdlkfj',
'route' => 'link',
),
),
'test' => array(
array(
'label' => 'aaaa',
'route' => 'link',
),
array(
'label' => 'bbbbb',
'route' => 'link',
),
),
),
...
How do I pull the 'test' config under navigation into my view helper instead of the default?
Upvotes: 0
Views: 103
Reputation: 13558
You are loading another navigation 'tree'. This tree must be setup independently and unfortunately, that does take a couple of steps. I have earlier explained how to fix this in this answer.
Basically, you have to create a second navigation factory, link the factory to a navigation service name and use that service name in your view helpers.
Upvotes: 1