PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Zend_View_Helper_Navigation

Prior to the 1.9 release, the menu helper (Zend_View_Helper_Navigation_Menu) did not render sub menus correctly. When onlyActiveBranch was TRUE and the option renderParents FALSE, nothing would be rendered if the deepest active page was at a depth lower than the minDepth option.

In simpler words; if minDepth was set to '1' and the active page was at one of the first level pages, nothing would be rendered, as the following example shows.

Consider the following container setup:


<?php
$container 
= new Zend_Navigation(array(
    array(
        
'label' => 'Home',
        
'uri'   => '#'
    
),
    array(
        
'label'  => 'Products',
        
'uri'    => '#',
        
'active' => true,
        
'pages'  => array(
            array(
                
'label' => 'Server',
                
'uri'   => '#'
            
),
            array(
                
'label' => 'Studio',
                
'uri'   => '#'
            
)
        )
    ),
    array(
        
'label' => 'Solutions',
        
'uri'   => '#'
    
)
));

The following code is used in a view script:


<?php echo $this->navigation()->menu()->renderMenu($container, array(
    
'minDepth'         => 1,
    
'onlyActiveBranch' => true,
    
'renderParents'    => false
)); ?>

Before release 1.9, the code snippet above would output nothing.

Since release 1.9, the _renderDeepestMenu() method in Zend_View_Helper_Navigation_Menu will accept active pages at one level below minDepth, as long as the page has children.

The same code snippet will now output the following:

<ul class="navigation">
    <li>
        <a href="#">Server</a>
    </li>
    <li>
        <a href="#">Studio</a>
    </li>
</ul>

Zend Framework