2009年10月27日星期二

Re: [fw-mvc] Custom Zend_Helper_Navigation_* helper

The big problem is Zend adds the helper path. Because all ZF helpers are inside Zend_Helper_Navigation_* and not Zend_Helper_*, the framework adds the namespace for these elements itself.


This is in most cases done *after* you added the namespaces youself (e.g. in application.ini). Therefore, Zend will always find its own helpers first (because it searches inside the most recent added namespaces first). If you create your own Navigation view helper and add your own My_View_Helper_* namespace, it all works fine.


As an example, I added my Navigation view helper here: http://pastie.org/671879. This works fine for all our Soflomo_View_Navigation_* helpers.


Regards, Jurian
--
Jurian Sluiman
Soflomo.com


Op Tuesday 27 October 2009 17:54:41 schreef petewilliams1983:
> Sorry, some of my code got mangled, it should be:
>
> $view = Zend_Layout::getMvcInstance()->getView();
> $view->addHelperPath(LIBRARY_PATH . '/My/View/Helper', 'My_View_Helper');
>
> Pete
>
> petewilliams1983 wrote:
> > I'm trying to create a custom helper for rendering menus, called
> > My_View_Helper_Navigation_CustomMenu. However, I can't work out how to
> > register and use it.
> >
> > I've tried putting this in the bootstrap:
> >
> > $view = Zend_Layout::getMvcInstance()->getView();
> > // Add custom view helper path $view->addHelperPath(LIBRARY_PATH .
> > '/My/View/Helper', 'My_View_Helper');
> >
> > This works fine for normal helpers, but not for ones within
> > Zend_View_Helper_Navigation. Calling the following in a view just throws
> > an exception:
> >
> > $this->navigation()->customMenu()->render();
> >
> > Do I have to register the helper separately with
> > Zend_View_Helper_Navigation or something? If so, how do I do this?
> >
> > Thanks,
> >
> > Pete

没有评论: