dongnue2071
2014-04-11 13:21
浏览 17
已采纳

如何将导航配置导入到我的视图助手中?

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?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • down00111 2014-04-11 13:32
    已采纳

    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.

    打赏 评论

相关推荐 更多相似问题