views:

464

answers:

2

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?

A: 

in my bootstrap:

$view = new Zend_View();
$view->addHelperPath(DE_Config::get('DE_appDir').DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'DE'.DIRECTORY_SEPARATOR.'View'.DIRECTORY_SEPARATOR.'Helper'.DIRECTORY_SEPARATOR, 'DE_View_Helper');
$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer();
$viewRenderer->setView($view);
Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
Karsten
The DIRECTORY_SEPARATOR constant is great for performing an explode() on file paths, but is unnecessary for specifying an include path. Forward slashes work fine in Windows and *nix platforms. (Just an FYI)
Sonny
+5  A: 

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; }
 }
gnarf
I tried what you commented with, `resources.view.helperPaths.My_View_Helper = APPLICATION_PATH "/views/helpers"` but it still can't find `Test`. Do you mind posting your working structure, using your ini file only?
meder
I'm selecting this as the answer because you provided me with the directory structure, although the way I actually solved it was by moving my bootstrap function which added encoding/doctype to the view at the start, before my other init methods and that somehow fixed it.
meder
@meder - You should be able to remove any doctype/encoding/etc stuff from the bootstrap all together, replacing it with proper configuration directives (which I'm pretty sure using the `[]` trick doesn't work in INI's) -- If you find that it isn't loading your settings quick enough `$this->boostrap('view');` at the top of your `_initApp()` function in your bootstrap should read/set all the settings then.
gnarf