Action Helpers Path configuration in version 1.9.5

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Action Helpers Path configuration in version 1.9.5

scabro
I’m just starting with Zend Framework and find it very frustraiting that all sources out there are referring to the previous versions of the framework – while I’m using the latest one (recommended) and can’t quite figure out how to replace all those configuration differences in the new version.
The problem I have is the Action Helpers – how can I register them – in other words where do I define the path to the action helpers folder.

I’ve seen several options - one with the Bootstrap.php by creating the method:

protected function _initActionHelpers() {
Zend_Controller_Action_HelperBroker::addPath(
APPLICATION_PATH.”/controllers/helpers”);
}

This however didn’t solve my problem – I’m still getting error: “Fatal error: Class ‘My_Action_Helper_Initializer’ not found in…”.

Then I’ve also tried to add the path to the application.ini file in the following way:

resources.frontcontroller.actionhelperpaths.Helper = APPLICATION_PATH “/controllers/helpers”

But this has caused another error.

Could you please explain how to register path to the Action Helpers in the Zend Framework 1.9.5/6 ?

I would really appreciate if someone could come up with the full explanation on how to do it – as for the first time runner with Zend it’s a nightmare to get it all up and running.

Regards,
Reply | Threaded
Open this post in threaded view
|

Re: Action Helpers Path configuration in version 1.9.5

weierophinney
Administrator
-- scabro <[hidden email]> wrote
(on Friday, 27 November 2009, 07:32 AM -0800):

> I’m just starting with Zend Framework and find it very frustraiting that all
> sources out there are referring to the previous versions of the framework –
> while I’m using the latest one (recommended) and can’t quite figure out how
> to replace all those configuration differences in the new version.
> The problem I have is the Action Helpers – how can I register them – in
> other words where do I define the path to the action helpers folder.
>
> I’ve seen several options - one with the Bootstrap.php by creating the
> method:
>
> protected function _initActionHelpers() {
> Zend_Controller_Action_HelperBroker::addPath(
> APPLICATION_PATH.”/controllers/helpers”);
> }
>
> This however didn’t solve my problem – I’m still getting error: “Fatal
> error: Class ‘My_Action_Helper_Initializer’ not found in…”.

You need to tell addPath() the class prefix that is used for classes in
that directory as well:

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

> Then I’ve also tried to add the path to the application.ini file in the
> following way:
>
> resources.frontcontroller.actionhelperpaths.Helper = APPLICATION_PATH
> “/controllers/helpers”
>
> But this has caused another error.

Again, you need to specify the class prefix used. Assuming the same
class prefix as quoted above, this can be done as follows:

   resources.frontcontroller.actionhelperpaths.My_Action_Helper = APPLICATION_PATH "/controllers/helpers"

If you use the above configuration, you won't need to define the helper
paths within your own class resource method.


--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
Reply | Threaded
Open this post in threaded view
|

Re: Action Helpers Path configuration in version 1.9.5

scabro
Hi Matthew,

Thanks very much for the instructions - I did try them, but for some reason they still didn't solve the problem.

Here's the structure of my folders:

Zend folder structure


My Class name inside of the application/controllers/helpers/Initializer.php is : My_Action_Helper_Initializer
and it extends Zend_Controller_Action_Helper_Abstract.

Inside of the application.ini I have added the following line:

resources.frontcontroller.actionhelperpaths.My_Action_Helper_Initializer = APPLICATION_PATH "/controllers/helpers"

and in the Bootstrap.php I've created the following, protected method:

protected function _initActionHelpers(){
    Zend_Controller_Action_HelperBroker::addPath(
    APPLICATION_PATH."/controllers/helpers",
    "My_Action_Helper_Initializer"
    );
}


However I'm still getting the error starting with:

Fatal error: Uncaught exception 'Zend_Application_Bootstrap_Exception' with message 'No default controller directory registered with front controller' in...

Also - does it mean that I need to specify separately path to each Action Helper rather than general one for all of them?

I appreciate your help.

Regards,
Reply | Threaded
Open this post in threaded view
|

Re: Action Helpers Path configuration in version 1.9.5

weierophinney
Administrator
-- scabro <[hidden email]> wrote
(on Friday, 27 November 2009, 01:38 PM -0800):

> Thanks very much for the instructions - I did try them, but for some reason
> they still didn't solve the problem.
>
> Here's the structure of my folders:
>
> http://n4.nabble.com/file/n802065/Picture%2B1.png 
> <br />
>
> My Class name inside of the application/controllers/helpers/Initializer.php
> is : My_Action_Helper_Initializer
> and it extends Zend_Controller_Action_Helper_Abstract.
>
> Inside of the application.ini I have added the following line:
>
> resources.frontcontroller.actionhelperpaths.My_Action_Helper_Initializer =
> APPLICATION_PATH "/controllers/helpers"
>
> and in the Bootstrap.php I've created the following, protected method:
>
> protected function _initActionHelpers(){
>     Zend_Controller_Action_HelperBroker::addPath(
>     APPLICATION_PATH."/controllers/helpers",
>     "My_Action_Helper_Initializer"
>     );
> }
>
> However I'm still getting the error starting with:
>
> Fatal error: Uncaught exception 'Zend_Application_Bootstrap_Exception' with
> message 'No default controller directory registered with front controller'
> in

You didn't read my reply correctly.

First, you have specified the full class name when setting the helper
paths -- when you need to specify the class *prefix* -- everything
leading up to the helper name.

So, your helper class is "My_Action_Helper_Initializer". The class
prefix is "My_Action_Helper", and the helper name is "Initializer". You
need to use the prefix, "My_Action_Helper", in your configuration.

Second, do ONE of the approaches: EITHER use configuration OR create the
resource method in your bootstrap, NOT both.

If you do configuration, do this:

    resources.frontcontroller.actionhelperpaths.My_Action_Helper = APPLICATION_PATH "/controllers/helpers"

If you create a resource method, do this:

    protected function _initActionHelpers()
    {
        Zend_Controller_Action_HelperBroker::addPath(
            APPLICATION_PATH . "/controllers/helpers",
            "My_Action_Helper"
        );
    }

Either one of those approaches *will* work.

Finally, a note: if this particular helper has preDispatch(),
postDispatch(), or init() hooks, you will want to actually instantiate
it and attach it to the helper broker during bootstrapping. I would do
it as follows: use the front controller configuration as described
above, and then create a resource method as follows:

    protected function _initActionHelpers()
    {
        $this->bootstrap('FrontController');
        $initializer = Zend_Controller_Action_HelperBroker::getStaticHelper('Initializer');
    }

This will ensure it's registered prior to any action controllers.

> Also - does it mean that I need to specify separately path to each Action
> Helper rather than general one for all of them?

If you follow my directions above, you can group your helpers under that
directory, and all will be available.

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
Reply | Threaded
Open this post in threaded view
|

Re: Action Helpers Path configuration in version 1.9.5

scabro
Thanks a lot Matthew - it works now!

Take care,