Search code examples
zend-frameworkzend-viewzend-navigation

How to render a parent and child active in a menu if they have the same URI and using Zend_Navigation?


Hello I'm digging into this problem without finding a solution. It seems very simple but I turn around for a while.

I'm trying to highlight a parent and 1 child in a menu. Both have the same uri, but only the parent is getting the active class.

Here my xml:

<configData>
<apps>
<agenda>
    <label>Agenda</label>
    <uri>/apps/agenda</uri>

    <pages>
        <page1>
            <label>Page 1</label>
            <uri>/apps/agenda</uri>
        </page1>
        <page2>
            <label>Page 2</label>
            <uri>/apps/agenda/page2</uri>
        </page2>
    </pages>
</agenda>
</apps>
</configData>

here my .phtml:

<div>
    <?php echo $this->navigation(Zend_Registry::get('Zend_NavigationApp'))->menu()
            ->renderMenu(null, array(
            'minDepth' => null,
            'maxDepth' => 1,
            'ulClass' => 'navigation',
            'onlyActiveBranch' => false));
            ?>
</div>

and here the generated html:

<div>
<ul class="navigation">

<li class="active">
    <a href="/apps/agenda">Agenda</a>
    <ul>
        <li> /*Here the expected active class*/

            <a href="/apps/agenda">Page 1</a>
        </li>
        <li>
            <a href="/apps/agenda/page2">Page 2</a>
        </li>
    </ul>
</li>

</ul>
</div>

All that I want to do is to get the "li" parent and "li" child with an active class after I clicked the parent link.


Solution

  • Solution

    Using MVC instead of URI style config xml file fixed all my problems.

    Here my fixed xml:

    <configData>
    <apps>
    <agenda>
        <label>Agenda</label>
        <module>module_1</module>
        <controller>control_1</controller>
        <action>action_1</action>
        <route>agenda_1</route>
    
        <pages>
            <page1>
                <label>Page 1</label>
                <module>module_1</module>
                        <controller>control_1</controller>
                        <action>action_1</action>
                        <route>agenda_1</route>
            </page1>
            <page2>
                <label>Page 2</label>
                <module>module_2</module>
                        <controller>control_2</controller>
                        <action>action_2</action>
                        <route>agenda_2</route>
            </page2>
        </pages>
    </agenda>
    </apps>
    </configData>
    

    Note that I'm using route definition in my ini file.