ZF:ZEND_NAVIGATION_PAGE - 页面未获得活动状态
我生成了带有这样的页面的菜单:
$pageSettings = array(
'route' => 'catalog',
'label' => $element->getName(),
'module' => 'default',
'controller' => 'catalog',
'action' => 'index',
'params' => array('cat' => $element->getUrl()),
'order' => $element->getOrder(),
'id' => 'catalogID_' . $element->getId(),
);
$contentMenuTree->addPage($pageSettings);
其中 $contentMenuTree
是一个 Zend_Navigation 实例。
并且在引导程序中有一条路线:
$router->addRoutes(array(
'catalog' => new Zend_Controller_Router_Route('/catalog/:cat', array('module' => 'default', 'controller' => 'catalog', 'index' => 'index', 'cat' => null))
));
如果我调用 site.ru/catalog/test 那么 $contentMenuTree 中没有任何活动页面。
所以我找到了它的补丁,但它似乎不正确:
$front = Zend_Controller_Front::getInstance();
$action = $front->getRequest()->getActionName();
$cat = $front->getRequest()->getParam('cat');
$module = $front->getRequest()->getModuleName();
$controller = $front->getRequest()->getControllerName();
if ($controller == 'catalog' && $module == 'default'
&& $action == 'index' && $cat==$element->getUrl())
$pageSettings['active'] = true;
Why zend_navigation does not get active page elementautomatic?
I have generated menu with pages like that:
$pageSettings = array(
'route' => 'catalog',
'label' => $element->getName(),
'module' => 'default',
'controller' => 'catalog',
'action' => 'index',
'params' => array('cat' => $element->getUrl()),
'order' => $element->getOrder(),
'id' => 'catalogID_' . $element->getId(),
);
$contentMenuTree->addPage($pageSettings);
Where $contentMenuTree
is a Zend_Navigation instance.
And have a route in a bootstrap:
$router->addRoutes(array(
'catalog' => new Zend_Controller_Router_Route('/catalog/:cat', array('module' => 'default', 'controller' => 'catalog', 'index' => 'index', 'cat' => null))
));
If I call site.ru/catalog/test then there are nothing active page in $contentMenuTree.
So I found patch for it but it doesn't seem correct:
$front = Zend_Controller_Front::getInstance();
$action = $front->getRequest()->getActionName();
$cat = $front->getRequest()->getParam('cat');
$module = $front->getRequest()->getModuleName();
$controller = $front->getRequest()->getControllerName();
if ($controller == 'catalog' && $module == 'default'
&& $action == 'index' && $cat==$element->getUrl())
$pageSettings['active'] = true;
Why zend_navigation doesn't get active page element automatically?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的路由器中没有
action
我认为它应该是
you don't have
action
in your routeri think it should be