PhpRiot
Follow phpriot on Twitter
Sponsored Link
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
Free iPad/iPhone App
Available on the App Store

  • PHP manual
  • Zend Framework manual
  • Smarty manual
  • PHP articles
  • PHP training

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