【问题标题】:ZF: ZEND_NAVIGATION_PAGE - page doesn't get active statusZF:ZEND_NAVIGATION_PAGE - 页面未获得活动状态
【发布时间】:2011-06-14 12:46:07
【问题描述】:

我已经生成了带有类似页面的菜单:

$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;

为什么 zend_navigation 没有自动获取活动页面元素?

【问题讨论】:

  • 补丁中有什么问题?你如何设置页面设​​置?
  • 在补丁中一切正常。但我认为 Zend_Navigation 应该可以在没有这个补丁的情况下工作。
  • 你是对的,ZF Navigation 也负责参数。 /catalog/index/cat/xyz 工作吗?
  • 请参阅framework.zend.com/manual/en/… 上的示例#4,据我所知,您做得非常正确。 $element->getUrl() 是否返回正确的 'cat' 值? vardump($navigation->toArray());
  • 你的路由器中没有action

标签: php zend-framework tree zend-navigation


【解决方案1】:

您的路由器中没有action

我觉得应该是

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

【讨论】:

    猜你喜欢
    • 2011-10-06
    • 1970-01-01
    • 1970-01-01
    • 2012-02-28
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多