0

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?

1 Answer 1

2

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>
Sign up to request clarification or add additional context in comments.

3 Comments

Thank's for your answer. I found the findOneBy('controller') approach in this tutorial link. If I search for a label instead a controller I actually obtain an output. But I only get the main menu. It seems to me, that Zend dosen't read in the XML structure correctly.
It could be that the xml is wrong. I have updated my answer. Please try the modified xml.
With your suggestion I am able to obtain an output. But I have still one problem with it. Let's say I have one more controller called 'device' with two more pages. If I render my submenu now I get a menu with all pages, which have a depth of one. But not separated by the particular controller. So I get a menu with all links from user and device, although I search for a particular label. It seems to me, that there is still something wrong with my XML.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.