Reputation: 13
I define all my pages in a XML file like the following:
<?xml version="1.0" encoding="UTF-8"?>
<configdata>
<nav>
<dashboard>
<label>Dashboard</label>
<module>default</module>
<controller>dashboard</controller>
<action>index</action>
<title>Die Schaltzentrale</title>
</dashboard>
<user>
<label>User</label>
<module>default</module>
<controller>user</controller>
<action>index</action>
<title>Verwaltung der Benutzer</title>
<userList>
<module>default</module>
<controller>user</controller>
<action>index</action>
<label>Userliste anzeigen</label>
</userList>
<newUser>
<label>User anlegen</label>
<module>default</module>
<controller>user</controller>
<action>new</action>
</newUser>
<editUser>
<label>User bearbeiten</label>
<module>default</module>
<controller>user</controller>
<action>edit</action>
</editUser>
</user>
</nav>
</configdata>
In my bootstrap I setup my navigation like this:
protected function _initNavigation()
{
$this->bootstrap('layout');
$layout = $this->getResource('layout');
$config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml','nav');
$view = $layout->getView();
$navigation = new Zend_Navigation($config);
$view->navigation($navigation);
Zend_Registry::set('Zend_Navigation',$navigation);
}
This setup enables me to render my main menu with the following lines:
$partial = array('menu.phtml', 'default');
$this->navigation()->menu()->setPartial($partial);
echo $this->navigation()->menu()->render();
So far so good. My problem is now to render a particular submenu. Let's say I want to render a menu with all actions of the user controller. I tried to render it with:
$page = $this->navigation()->findOneBy('controller','user');
echo $this->navigation()->menu()->renderMenu($page);
But I got no output. I also tried to obtain an output by setting the minDepth or maxDepth option without any success. Has anyone a hind for me, how I can bring it to work?
Upvotes: 0
Views: 2677
Reputation: 14862
Your approach is very close. Change the findOneBy line to:
$page = $this->navigation()->findOneBy('label','User');
This will fetch all the pages under the User page.
I do not think it is possible to find a page by controller.
[edit]
I have modified your xml by adding a 'pages' section under user. This tells Zend Navigation that userList, newUser and editUser are sub-pages of user:
<?xml version="1.0" encoding="UTF-8"?>
<configdata>
<nav>
<dashboard>
<label>Dashboard</label>
<module>default</module>
<controller>dashboard</controller>
<action>index</action>
<title>Die Schaltzentrale</title>
</dashboard>
<user>
<label>User</label>
<module>default</module>
<controller>user</controller>
<action>index</action>
<title>Verwaltung der Benutzer</title>
<pages>
<userList>
<module>default</module>
<controller>user</controller>
<action>index</action>
<label>Userliste anzeigen</label>
</userList>
<newUser>
<label>User anlegen</label>
<module>default</module>
<controller>user</controller>
<action>new</action>
</newUser>
<editUser>
<label>User bearbeiten</label>
<module>default</module>
<controller>user</controller>
<action>edit</action>
</editUser>
</pages>
</user>
</nav>
</configdata>
Upvotes: 2