-- jasonzfw <[email protected]> wrote
(on Friday, 23 January 2009, 01:22 PM -0800):
> beberlei wrote:
> > 
> > I would extend Zend_Controller_Action and make an application wide
> > action controller that has the init function which centralizes all the 
> > duplicated code.
> > 
> 
> But I thought the purpose of using an action helper was to avoid exactly
> this, as has been stated earlier in this thread? Extending the
> Zend_Controller_Action is the easiest way to achieve this goal, but articles
> such as 
> http://devzone.zend.com/article/3350-Action-Helpers-in-Zend-Framework
> http://devzone.zend.com/article/3350-Action-Helpers-in-Zend-Framework  state
> this is not the appropriate approach.
> 
> Basically I'm under the impression I can call this action helper statically
> within the bootstrap.php file, like so:
> 
> $initStuff =
> Zend_Controller_Action_HelperBroker::getStaticHelper('InitializeStuff');
> 
> From there, it seems there should be some way to make certain variables
> available in each controller's $this scope, perhaps using a callback within
> the action helper. However this is the part of the puzzle that continues to
> escape me.

Within your action helper's init() or preDispatch() method, do something
like this:

    $controller = $this->getActionController();
    $controller->foo = 'bar';

This will set the public 'foo' property of the current action controller
to the value 'bar'. We actually do this with the ViewRenderer to set the
'view' property.

-- 
Matthew Weier O'Phinney
Software Architect       | [email protected]
Zend Framework           | http://framework.zend.com/

Reply via email to