title: How do I extend the Zend Navigation Menu View Helper?
body: <p>I need to change the output of <code>Zend_View_Helper_Navigation_Menu</code>.  I've found the two functions that I'll need to modify, and I know how to make the changes I need.  What I don't know is how to make the Navigation object use my view helper instead of the Zend one.</p>
  
  <p>Code snippet representing my class extension:</p>
  
  <pre><code>// file /library/My/View/Helper/Navigation/Menu.php
  class My_View_Helper_Navigation_Menu extends Zend_View_Helper_Navigation_Menu
  {
      protected function _renderDeepestMenu(Zend_Navigation_Container $container,
                                            $ulClass,
                                            $indent,
                                            $minDepth,
                                            $maxDepth)
      {
          // modified code here
      }
  
      protected function _renderMenu(Zend_Navigation_Container $container,
                                     $ulClass,
                                     $indent,
                                     $minDepth,
                                     $maxDepth,
                                     $onlyActive)
      {
          // modified code here
      }
  }
  </code></pre>
  
  <hr>
  
  <p><strong>Edits to Clarify</strong></p>
  
  <p>I want to change the class of the <code>&lt;li&gt;</code> elements and remove the <code>EOL</code> and indentation.  There are no options to do that with the menu view script, which is why I'll have to extend it.</p>
  
  <p>Initializing the navigation object in my Bootstrap:</p>
  
  <pre><code>$navTable = new Default_Model_Site_DbTable_Navigation();
  $view = $this-&gt;getResource('view');
  $view-&gt;navigation(new Zend_Navigation($navTable-&gt;getNavigation()));
  </code></pre>
  
  <p>Rendering the menu in my layout:</p>
  
  <pre><code>echo $this-&gt;navigation()-&gt;menu();
  </code></pre>
  
  <hr>
  
  <p><strong>Solution</strong></p>
  
  <p>I got it working by renaming things as follows, but I am not clear on why I can't overload/overwrite the <code>_Menu</code> class and <code>menu()</code> function.</p>
  
  <ol>
  <li>Change the class name to <code>My_View_Helper_Navigation_MyMenu</code></li>
  <li>Add the <code>myMenu</code> function to the the class (<code>return parent::menu($container);</code>)</li>
  <li>Call <code>echo $this-&gt;navigation()-&gt;myMenu();</code> in the layout</li>
  </ol>
  
  <p>Class wireframe:</p>
  
  <pre><code>// file /library/My/View/Helper/Navigation/MyMenu.php
  class My_View_Helper_Navigation_MyMenu extends Zend_View_Helper_Navigation_Menu
  {
      public function myMenu(Zend_Navigation_Container $container = null)
      {
          return parent::menu($container);
      }
  
      protected function _renderDeepestMenu(Zend_Navigation_Container $container,
                                            $ulClass,
                                            $indent,
                                            $minDepth,
                                            $maxDepth)
      {
          // modified code here
      }
  
      protected function _renderMenu(Zend_Navigation_Container $container,
                                     $ulClass,
                                     $indent,
                                     $minDepth,
                                     $maxDepth,
                                     $onlyActive)
      {
          // modified code here
      }
  }
  </code></pre>