创建单个zend导航页面时,将禁用活动状态

时间:2017-01-12 19:44:03

标签: php zend-framework zend-framework2

我有以下代码:

class Module {
    public function onBootstrap(MvcEvent $e){ 
       $application = $e->getApplication();
       $em = $application->getEventManager();
       $em->attach(\Zend\Mvc\MvcEvent::EVENT_DISPATCH, array($this,'setupNav'),10000);
    }

    public function setupNav($e)
    {
        $serviceLocator = $e->getApplication()->getServiceManager();
        $router = $serviceLocator->get('router');
        $page = \Zend\Navigation\Page\AbstractPage::factory(array(
                'label' => 'Login',
                'route' => 'login', 
                'resource' => 'auth.auth.login'                                     
        ));         
        $page->setRouter($router);
        $page->set('type','user');
        $serviceLocator->get('navigation')->addPage($page); 
    }
}

问题在于,当路由匹配时,我动态创建的这些页面不会被标记为活动状态(并添加active class)。它适用于加载navigation container (the config navigation)的内容但由于某种原因,当我动态添加Mvc Pages 时,状态不会对这些导航元素生效

0 个答案:

没有答案