0

I'm looking at refactoring some code out of an Actions postDispatch into a plugin. The code currently is assigning a value to the view object and I can't find out how to get access to the view object from inside the plugin.

The old Zend_Controller_Action::postDispatch():

public function postDispatch() {
  ...
  $this->view->flashMessages = array_merge($flashMessenger->getCurrentMessages(), $flashMessenger->getMessages());
  ...
}

The new Zend_Controller_Plugin_Abstract::postDispatch():

public function postDispatch(Zend_Controller_Request_Abstract $request) {
  ...
  // How to get access to Zend_Controller_Action::$view?
  // $this->view->flashMessages = array_merge($flashMessenger->getCurrentMessages(), $flashMessenger->getMessages());
  ...
}

Is there a straight forward way to do this?

hafichuk
  • 10,351
  • 10
  • 38
  • 53
  • 2
    http://stackoverflow.com/questions/4907490/getting-view-object-from-within-a-zend-controller-plugin – thetaiko Nov 16 '11 at 18:36

2 Answers2

0

Try this:

public function postDispatch(Zend_Controller_Request_Abstract $request)
{
    $flashMessages = Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger')->getMessages();

    $view = Zend_Layout::getMvcInstance()->getView();
    $view->flashMessages = $flashMessages->getCurrentMessages();
}
Tim Fountain
  • 33,093
  • 5
  • 41
  • 69
0
$view = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('view');
Pavel Tytyuk
  • 119
  • 2