I am putting together a Zend Navigation for a site with 4 different levels of access: Guest, Member1, Member2, and Admin.
My navigation XML looks something like this:
<?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>
Since I am using submenus and want consistency for top menu, I want to use a Zend's findBy feature to locate current user's status and display that menu. This is done as such:
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);
}
My Bootstrap bit for Nav is pretty generic and looks like this:
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());
}
Now, I can get the "Member1 Main" page to appear, but it only shows that one page, but what I need to render is that page's whole submenu. It seems that findOneByLabel only looks up that particular page only and not its descendants. Is there a way to pull the whole submenu?
Thanks.