Bryan
Bryan

Reputation: 645

Pass data from controller action helper to view automatically in Zend Framework

I have created an actionHelper with a preDispatch function. I want this preDispatch to send some data to my view. Any idea how I can achieve this?

Upvotes: 0

Views: 1212

Answers (3)

i--
i--

Reputation: 4360

$view = Zend_Layout::getMvcInstance()->getView();
$view->yourVar = 'test';

Upvotes: 0

David Weinraub
David Weinraub

Reputation: 14184

Alternatively (from within your action helper):

$view = $this->getActionController()->view;
$view->myKey = 'myValue';

An action helper is one of the few places in a ZF app that has direct access to the controller instance (as opposed to the controller name, which is accessible in lots of ways in various places).

Upvotes: 4

tawfekov
tawfekov

Reputation: 5122

hey this would be as easy as this :)

$view = Zend_Controller_Action_HelperBroker::getExistingHelper('ViewRenderer')->view; 
$view->your_param  = $your_value ;

then you could access it as usually

Upvotes: 1

Related Questions