I am trying to simply use a custom view helper that is located in /library/my/view/helpers/friends.php
I have this in the application.ini:
resources.view.helperPath.My_View_Helper = "/my/view/helpers"
This is the helper class:
class My_View_Helper_Friends extends Zend_View_Helper_Abstract {
public function friends() {
$str = "hello world";
return $str;
}
}
This is in the view file:
<?php echo $this->friends(); ?>
I get an error on this line saying it can’t find the plugin in a path that it is already in.
The error:
Plugin by name ‘Friends’ was not found in the registry; used paths:
My_View_Helper_: /My/View/Helpers/ Zend_View_Helper_:
Zend/View/Helper/;C:/http/xampplite/htdocs/zf-tutorial/application/views\helpers/
Looks like its using the right path and the file is there. I don’t understand why it can’t find it?
I believe the problem is that the incorrect path is being used.
Note how the path is
/My/View/Helpers. It is using an absolute path. The other issue is that the folder should be namedHelperinstead ofhelpers.Then change the config line in your
application.inito this:and make sure your class is called
My_View_Helper_Friendsand the file is namedFriends.php. Case matters. The directory should really be calledMy/View/Helperwith caps.EDIT: Assuming
libraryis in yourinclude_path, you could also use the line:Notice how it doesn’t have the leading
/. This will search all locations in yourinclude_pathfor a folderMy/View/Helper.