开发者

ZF: ZEND_NAVIGATION_PAGE - page doesn't get active status

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?


you don't have action in your router

i think it should be

$router->addRoutes(array(            
    'catalog'  => new Zend_Controller_Router_Route('/catalog/:cat', 
     array('module' => 'default', 
           'controller' => 'catalog', 
           'action' => 'index',
           'cat' => null))
));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜