我正在为具有 4 个不同访问级别的站点组合 Zend Navigation:Guest、Member1、Member2 和 Admin。
我的导航 XML 看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<nav>
<default>
<label>Home</label>
<controller>index</controller>
<action>index</action>
<resource>index</resource>
<privilege>index</privilege>
<pages>
<home>
...
</home>
<signin>
...
</signin>
<signup>
...
</signup>
</pages>
</default>
<member1>
<label>Member1 Main</label>
<controller>member1</controller>
<action>index</action>
<resource>member1</resource>
<privilege>index</privilege>
<pages>
<dashboard>
...
</dashboard>
<settings>
<label>Settings</label>
<controller>auth</controller>
<action>editpassword</action>
<resource>auth</resource>
<privilege>editpassword</privilege>
<class>settings</class>
<title>User settings</title>
<pages>
<account>
...
</account>
<logout>
...
</logout>
</pages>
</settings>
</pages>
</member1>
<member2>
<label>Member2 Main</label>
<controller>member2</controller>
<action>index</action>
<resource>member2</resource>
<privilege>index</privilege>
<pages>
<dashboard>
...
</dashboard>
<profile>
...
</profile>
<settings>
<label>Settings</label>
<controller>auth</controller>
<action>editpassword</action>
<resource>auth</resource>
<privilege>editpassword</privilege>
<class>settings</class>
<pages>
<account>
...
</account>
<logout>
...
</logout>
</pages>
</settings>
</pages>
</member2>
<admin>
<label>Dashboard</label>
<controller>admin</controller>
<action>index</action>
<resource>admin</resource>
<privilege>index</privilege>
<pages>
<dashboard>
...
</dashboard>
<logout>
...
</logout>
</pages>
</admin>
</nav>
</config>
由于我正在使用子菜单并希望顶部菜单保持一致,因此我想使用 Zend 的findBy功能来定位当前用户的状态并显示该菜单。这样做是这样的:
if ( $this->user ) {
$submenu = $this->navigation()->findOneByLabel('Member1 Main');
$options = array(
'ulClass' => 'navigation',
'renderParents' => true,
'minDepth' => null,
'maxDepth' => null
);
echo $this->navigation()->menu()->renderMenu($submenu, $options);
} else {
echo $this->navigation()->menu()->setUlClass('navigation')->setOnlyActiveBranch(true)->setMinDepth(1)->setMaxDepth(1);
}
我的 Nav 引导位非常通用,如下所示:
function _initNavigation()
{
$this->bootstrap('layout');
$layout = $this->getResource('layout');
$view = $layout->getView();
$navConfig = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml', 'nav');
$navigation = new Zend_Navigation($navConfig);
$front = Zend_Controller_Front::getInstance();
$myPlagin = $front->getPlugin('My_Controller_Plugin_Acl');
$view->navigation($navigation)->setAcl($myPlagin->getMyAcl())
->setRole($myPlagin->getMyUserRole());
}
现在,我可以让“Member1 Main”页面出现,但它只显示一个页面,但我需要呈现的是该页面的整个子菜单。似乎findOneByLabel仅查找该特定页面而不查找其后代。有没有办法拉整个子菜单?
谢谢。