我在使用 Zend_Navigation 设置面包屑和菜单时遇到问题。
首先,我使用 XML 配置对象设置我的页面:
<?xml version="1.0" encoding="UTF-8"?>
<configdata>
<nav>
<home>
<label>Home</label>
<controller>Index</controller>
<action>index</action>
<id>home</id>
<resource>default</resource>
</home>
<crm>
<label>CRM</label>
<module>Crm</module>
<controller>Index</controller>
<action>index</action>
<id>crm</id>
<resource>Crm</resource>
<pages>
<persons>
<module>Crm</module>
<label>Personen</label>
<controller>Persons</controller>
<action>index</action>
</persons>
(...)etc.(...)
然后在我的引导程序中:
//Bootstrap.php
$view = $layout -> getView();
$config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml', 'nav');
$navigation = new Zend_Navigation($config);
$view -> navigation($navigation);
$view -> menu = $view -> navigation() -> menu();
$view -> breadcrumbs = $view -> navigation()->breadcrumbs()->setMinDepth(0);
现在,如果我要导航到http://hostname/Crm/Persons/
活动状态,那么面包屑也会正确显示。
但是,当我转到http://hostname/Crm/Persons/inspect/id/3
(其中检查是操作,id 是参数)时,面包屑将为空,并且所有菜单项都不会处于活动状态。预期的面包屑类似于:Home > CRM > Personen > John
并且 CRM 和 Personen 应该在菜单中处于活动状态。
现在 Zend 文档给了我一个线索:它可能因为设置了参数而无法工作。
/*
* Dispatched request:
* - module: blog
* - controller: post
* - action: view
*/
$page = new Zend_Navigation_Page_Mvc(array(
'action' => 'view',
'controller' => 'post',
'module' => 'blog',
'params' => array('id' => null)
));
// returns false, because page requires the id param to be set in the request
$page->isActive(); // returns false
我不知道如何解决这个问题。思想受到高度赞赏。