0

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?

Bryan
  • 645
  • 1
  • 6
  • 18

3 Answers3

4

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

David Weinraub
  • 14,144
  • 4
  • 42
  • 64
  • It says undefined method getActionController() – Abdul Basit Jul 07 '15 at 07:42
  • @AbdulBasit Are you sure you are making this call from within your action-helper that extends `Zend_Controller_Action_Helper_Abstract`? The method is there, certainly [since 1.12.0](https://github.com/zendframework/zf1/blob/release-1.12.0/library/Zend/Controller/Action/Helper/Abstract.php#L68) – David Weinraub Jul 07 '15 at 08:41
1

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

tawfekov
  • 5,084
  • 3
  • 28
  • 51
0
$view = Zend_Layout::getMvcInstance()->getView();
$view->yourVar = 'test';
i--
  • 4,349
  • 2
  • 27
  • 35