我有以下代码:
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
时,状态不会对这些导航元素生效