我正在考虑将一些动作postDispatch中的代码重构为一个插件。代码当前正在为视图对象赋值,我无法找到如何从插件内部访问视图对象。
旧的Zend_Controller_Action :: postDispatch():
public function postDispatch() {
...
$this->view->flashMessages = array_merge($flashMessenger->getCurrentMessages(), $flashMessenger->getMessages());
...
}
新的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());
...
}
有没有直接的方法来做到这一点?
答案 0 :(得分:0)
试试这个:
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();
}
答案 1 :(得分:0)
$view = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('view');