I\'m using Zend_Navigation (sweet addition to the framework, btw) to build my menu, after which it should be rendered in the page (self-evidently). I first set the container
Sorry, for the formatting issue on the previous post
To add your custom helper do the following, in your bootstrap:
protected function _initNavigation()
{
$this->bootstrap('view'); // make sure we have a view
$view = $this->getResource('view'); // get the view resource
$config = new Zend_Config_Xml(APPLICATION_ROOT . '/config/navigation.xml','nav');
$container = new Zend_Navigation($config);
$view->navigation($container);
// Tell Zend were it can find your custom helpers and what
// the prefix is going to be.
$view->addHelperPath(
APPLICATION_ROOT . '/library/MyApp/View/Helper/Navigation',
'MyApp_View_Helper_'
);
}
Next create your custom view helper and put it in the ‘addHelperPath’ path. Depending on what you want to do you need to implement at least your own htmlify function. Take a look at Zend/View/Help/Navigation/Menu.php as an example.
class MyApp_View_Helper_MyMenu extends Zend_View_Helper_Navigation_Menu
{
public function myMenu(Zend_Navigation_Container $container = null)
{
if (null !== $container) {
$this->setContainer($container);
}
return $this;
}
protected function htmlify(Zend_Navigation_Page $page )
{
...
}
}
Next, in your phtml script:
navigation()->myMenu()->setMaxDepth(0); ?>
or just
navigation()->myMenu(); ?>
Now if you want to add your own custom properties to the generated HTML you can add them to your navigation ini or xml file. For example:
/
/images/MyIcon.gif
The custom xml tag will be stored as a property of the navigation page and can be fetched like:
foreach ($iterator as $page) {
...
$properties = new Zend_Config($page->GetCustomProperties());
$myPicture = $properties->img->src;
...
}
Hope this helps. Peter