2009年8月7日星期五

Re: [fw-mvc] Creating action helper in zend frameworl 1.9

-- Joó Ádám <ceriak@gmail.com> wrote
(on Friday, 07 August 2009, 08:29 PM +0200):
> Sorry, but it's still not clear for me.
>
> I have my action helper Joo_Controller_Action_Helper_Session placed in
> /library/Joo/Controller/Action/Helper/Session.php. What should I add
> to my application.ini to get it run?

You need to inform the front controller resource of the action helper
path. You do that with the "actionhelperpaths" key, and specify keys
corresponding to the prefix and values corresponding to the path:

resources.frontcontroller.actionhelperpaths.Joo_Controller_Action_Helper = "Joo/Controller/Action/Helper"

The problem, however, is that keys are flattened to lowercase within the
bootstrap, so the better solution is to simply create your own resource
method that either statically initializes the paths, or takes an
alternate configuration.

For instance, this is the static way:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initActionHelpers()
{
Zend_Controller_Action_HelperBroker::addPath(
'Joo/Controller/Action/Helper',
'Joo_Controller_Action_Helper',
);
}
}

and this would be a more configuration driven way:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initActionHelpers()
{
$config = $this->getOptions('actionhelperpaths');
if (empty($config)) {
return;
}

foreach ($config as $path) {
Zend_Controller_Action_HelperBroker::addPath(
$path['path'],
$path['prefix'],
);
}
}
}

In the above case, you'd add paths to your config as follows:

actionhelperpaths.joo.path = "Joo/Controller/Action/Helper"
actionhelperpaths.joo.prefix = "Joo_Controller_Action_Helper"

(where "joo" is simply an arbitrary string to group related paths and
prefixes)

--
Matthew Weier O'Phinney
Project Lead | matthew@zend.com
Zend Framework | http://framework.zend.com/

没有评论: