0

I want to create different folders insides my views/helpers and add my view helper classes inside them. But I am not able to access those classes.

What is the best way to do this?

I tried adjusting my application.ini file settings ... but no luck

This is what I have set inside my ini file:

resources.view.helperPath = APPLICATION_PATH "/views/helpers/models"
resources.view.helperPath = APPLICATION_PATH "/views/helpers/test"

models and test are the sub-folders inside my /views/helpers folder

Can anyone suggest a better solution?

t0mm13b
  • 34,087
  • 8
  • 78
  • 110
lak
  • 1
  • 1

3 Answers3

2

With your current setting in your application.ini you only add another path for the default view helpers from Zend (Zend_View_Helper_).

You have to specify the class prefix which you want to use:

; View_Helper_Models is the class prefix
resources.view.helperPath.View_Helper_Models = APPLICATION_PATH "/views/helpers/models"
; View_Helper_Test is the class prefix
resources.view.helperPath.View_Helper_Test = APPLICATION_PATH "/views/helpers/test"

Now the application knows how to map your class name to the path. Alternative you can enable this in your main Bootstrap.php:

protected function _initViewHelper()
{
   $this->bootstrap( 'view' );
   $this->_view = $this->getResource( 'view' );

   $this->_view->addHelperPath( APPLICATION_PATH . '/views/helpers/models',
                                'View_Helper_Models' );
   $this->_view->addHelperPath( APPLICATION_PATH . '/views/helpers/test',
                                'View_Helper_Test' );
}

NOTE: The path must be in the right case.

ByteNudger
  • 1,545
  • 5
  • 29
  • 37
0

In your config file add these two lines second line is your custom path to helpers

resources.view[] =    
resources.view.helperPath.Zend_View_Helper = APPLICATION_PATH "/../library/FolderA/FolderB/helpers"

While creating a Helper give the class name like this

<?php
class Zend_View_Helper_Foo extends Zend_View_Helper_Abstract
{
   public function foo(){
       echo 'hello world';
   }
}

and call that helper in any of your view files as $this->foo();

coolguy
  • 7,866
  • 9
  • 45
  • 71
-1

I think that you need only put the correct name of your view helper classes! For example, you create a file "Mine.php" inside APPLICATION_PATH "/views/helpers/models" and then you name the class as class View_Helper_Models_Mine

Hope this help.

Regards, Ahmed B.

Ahmed B
  • 9
  • 3