1

I'm pretty much newbie in Zend Framework action helpers and I am trying to use them with no success (I read a bunch of posts about action helpers, including http://devzone.zend.com/article/3350 and found no solution in like 8 hours). I used Zend Tool to setup my project and the name of the helper is Action_Helper_Common. No matter what I do, I get following error "Fatal error: Class 'Action_Helper_Common' not found". Currently, I have things set up like this:

  • zf version: 1.11.3
  • helper name: Action_Helper_Common
  • helpers location: /application/controllers/helpers/Common.php

In Bootstrap.php i have following function:

    protected function _initActionHelpers() {
    Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH . '/controllers/helpers', 'Action_Helper');
    Zend_Controller_Action_HelperBroker::addHelper(
        new Action_Helper_Common(null, $session)
    );
}

I also tried this without success (it was defined in Bootstrap.php before _initActionHelpers):

protected function _initAutoloader() {
    $moduleLoader = new Zend_Application_Module_Autoloader(array(
        'namespace' => '', 
        'basePath'  => APPLICATION_PATH . '/controllers/helpers'));
    return $moduleLoader;
}

So what am I doing wrong?!?! PLZ help, I am desperate and about to give up :)

Pavle Gartner
  • 659
  • 1
  • 7
  • 21

3 Answers3

0

you dont need to do (so remove it)

Zend_Controller_Action_HelperBroker::addHelper(
        new Action_Helper_Common(null, $session)
    ); ,

since you already did

Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH . '/controllers/helpers', 'Action_Helper');

when you will do

$myhelper = $this->getHelper('Common');

in your controller zf will lookinto directory /controllers/helpers/ for class name Action_Helper_Common and create an instance for you and return it.

Mr Coder
  • 8,169
  • 5
  • 45
  • 74
0

For some reason the following line didn't work for me as well:

Zend_Controller_Action_HelperBroker::addHelper( new Action_Helper_Common() );

I just keep getting a 'Class not found' error each time I'm creating a new helper object explicitly.

This is what works for me:

Zend_Controller_Action_HelperBroker::getHelper('Common');

In this case, new Action_Helper_Common object gets created and is registered with Helper Broker.

Not sure though if it works for you, since you have a parameterized constructor.

Vika
  • 3,275
  • 18
  • 16
0

You got error because you haven't setup autoloader for Action_Helper_*

Resource autoloader

Helper broker uses plugin loader to load helpers based on paths and prefixes you specified to it. That is why ::getHelper() can find your helper

Xerkus
  • 2,695
  • 1
  • 19
  • 32
  • Thanks man! That's just what I wanted, it works now by setting autoloader namespace to 'Action' with basePath "APPLICATION_PATH . '/controllers/helpers'" and specifying resourceType Helper. – Pavle Gartner Mar 01 '11 at 10:14
  • `if($classname = Zend_Controller_Action_HelperBroker::getPluginLoader()->load('Common')) { $helper = new $classname()}` This is other way to load your helper – Xerkus Mar 01 '11 at 15:54