views:

1227

answers:

4

Hi,

I begin with ZF (1.9.7), and I want to use View Helpers from a library shared between all my projects. But I can't find how to add it directory to the helpers path. My herpers works fines when I put them in application's helpers path.

Here is the error, where I find the path to ZF helpers, and path to the applications ones.

object(ArrayObject)#71 (3) {
  ["exception"]=>
  object(Zend_Loader_PluginLoader_Exception)#70 (6) {
    ["message:protected"]=>
    string(151) "Plugin by name 'Voo' was not found in the registry; used paths:
Zend_View_Helper_: Zend/View/Helper/;C:/ZendStd/www/applis/VOO4_PROJECTX/views\helpers/"
    ["string:private"]=>
    string(0) ""
    ["code:protected"]=>
    int(0)
    ["file:protected"]=>
    string(89) "C:\Program Files\Zend\ZendServer\share\ZendFramework\library\Zend\Loader\PluginLoader.php"
    ["line:protected"]=>
    int(401)

Best regards
Cédric

+3  A: 

Helper paths are added through Zend_View_Abstract::addHelperPath(). You can call this method directly on an existing View instance.

Helper paths can also be configured in various ways during bootstrap. Check out the ZF manual chapter on Zend_Application to see how to use Bootstrap classes and resources:

Gordon
Although all these options are correct, and will work, I feel the `application.ini` solution suggested by David to be the "best-practice". Also, in your "_initView()" you could use `$this->bootstrap('view'); $view = $this->getResource('view');` to use the application.ini view instead of one you randomly create...
gnarf
@gnarf with the exception of `addHelperPath()`, the bootstrap example is copied 1:1 from the ZF reference guide. It shouldn't be taken as anything else but an example. I am well aware there is different ways to do it (e.g. using an Ini). Feel free to do it differently.
Gordon
this links are not helpfull - zf documentation is pure in general and particular for helpers didn't contains real examples
se_pavel
+8  A: 

It can be done very easily with the built in Zend_Application resource for the view. If you're using ini configs, add a line like this:

resources.view.helperPath.My_View_Helper = "My/View/Helper"

The end of the key is the class name prefix, and the value the path where they reside.

David Caunt
A: 

I have written short simple tutorial for registering the zend view helpers from a common directory, which can be accessed throughout the application. Please have a look.

http://www.mixedwaves.com/2010/03/accessing-and-using-zend-view-helpers-from-a-common-directory/

Penuel
A: 

Hi Penuel, oh man your post helped me a lot, please tell me where I can get all the info about these newest architectural updates on zend frameork application?

I also would like to get a normal reference on Layouts, Helpers, Plugins etc. There is a lot of documentation around but you need to waste hours to get something useful.

Many thanks

Giorgi

zautashvili