OEIC

Zend Framework: View Helpers

I’m working on a project using the Zend Framework 0.9.3, and I had a bit of a snag implementing a custom view helper. Though it is mentioned in the documentation, there is so much emphasis on class naming and the framework controllers use the convention of having identical file and class names that it is easy to miss that:

The filename for your view helper should be named after the helper method, not the helper class.

As an example, if you have a method called HelperMethod() inside a class called View_Helper_HelperMethod, the filename should be HelperMethod.php.

Not currently noted in the documentation is that if you use the magic controller method initView() (and possibly instantiating a new Zend_View, though I haven’t tested this) to create your view object, that the view helper pathincludes ‘yourViewDir/helpers’. If you’re using the conventional application layout, this means that you don’t have to call $view->setHelperPath() or $view->addHelperPath() in all your controllers (though obviously this can be avoided through other OO means as well).

I’m not sure if this is new to version 0.9.3, or the docs haven’t been updated in a while, but the framework will magically look for helpers in the eponymously named directory, in addition to documented “Zend/View/Helper/” library directory.

No comments     Jump to comment form | comments rss | trackback uri

Say what?

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>





About this entry

Categories