1
votes

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 :)

3

3 Answers

0
votes

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.

0
votes

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.

0
votes

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