Zend: Where/how can I register custom view helpers

zend-framework

In my layout.phtml file I have :

<?php echo $this->Test(); ?>

I have created a Test view helper at application/views/helpers/Test.php

<?php 

class My_View_Helper_Test extends Zend_View_Helper_Abstract {

    public function Test() {
        return 'test';
    }

}

And my config file @ configs/application.ini:

resources.view[] = ''
resources.view.helperPath = APPLICATION_PATH "/views/helpers"

Error I get:

Zend_Loader_PluginLoader_Exception:
Plugin by name 'Test' was not found in
the registry; used paths:
Zend_View_Helper_:
Zend/View/Helper/:./views/helpers/ in
/usr/share/php/Zend/Loader/PluginLoader.php
on line 406

On a similar note I can't register my admin view helper either..

resources.view.helperPath.Admin_View_Helper = APPLICATION_PATH "/modules/admin/views/helpers"

My modules/admin/views/helpers/AdminPanel.php:

<?php

class My_View_Helper_AdminPanel extends Zend_View_Helper_Abstract {

public function AdminPanel() { return 'test'; }

}

Do I have no choice but to do this in the Bootstrap with addHelperPath? If so could someone demonstrate how I would using my paths?

Best Answer

Using application.ini is probably the best way to define these. I put all my view helpers inside my library folder:

includePaths.library = APPLICATION_PATH "/../library"
autoloadernamespaces.0 = "SNTrack_"

;  -- Note, these are the only resources.view lines I have...
resources.view.doctype = "XHTML1_STRICT"
resources.view.helperPath.SNTrack_View_Helper = APPLICATION_PATH "/../library/SNTrack/View/Helper"

Directory structure:

/
  application/
  library/
    SNTrack/
      View/
        Helper/
          Test.php

View:

 $this->test('test')

SNTrack/View/Helper/Test.php:

 class SNTrack_View_Helper_Test extends Zend_View_Helper_Abstract {
   public function test($args) { return $args; }
 }
Related Topic