ryy705
ryy705

Reputation: 637

How can I setup View helpers in the views directory?

I want to setup a helpers directory under views and place my view helpers there.

I have setup a test view helper in application/My/App/View/Helper/

I declared the class like so: class My_App_View_Helper_test extends Zend_View_Helper_Abstract

I setup the the Bootstrap.php file like so: $view->setHelperPath(APPLICATION_PATH.'/My/App/View/Helper','My_App_View_Helper');

This is working perfectly. I learned to do this from zendcasts. But I cannot set it up the way I want to. How do I set up helpers in views/helpers/ ? What are the rules regarding the directory naming conversion? Where do I use plural and where do I use capitalization when naming directories?

I thank you in advance for your help.

sincerely, a complete noob

Upvotes: 0

Views: 835

Answers (2)

Vika
Vika

Reputation: 3285

You can have a helper named Application_View_Helper_MyHelper in application/views/helpers.

In your bootstrap you should have the following:

$view->setHelperPath(APPLICATION_PATH.'/views/helpers','Application_View_Helper');

Here, you simply register new plugin prefix for view helpers - Application_View_Helper and point Zend Framework to look for classes with this prefix in the following path - APPLICATION_PATH.'/views/helpers

Upvotes: 1

JohnP
JohnP

Reputation: 50009

You can place the helpers in /view/helpers but you'll need to change your class name. The prefix needs to be Zend_View_Helper_

So, a class like Zend_View_Helper_MyHelper should work for you.

I found a blog post on usage, if you're interested : http://akrabat.com/zend-framework/zend-framework-view-helpers/

From the post

A typical Zend Framework project using Zend_Application, such as that generated using the zf command line tool, will have a folder called helpers within the views folder for each module. There will also be a helpers folder within the layouts folder too. If you place your view helper in one of these helpers folders, then the prefix is Zend_View_Helper_.

Upvotes: 1

Related Questions