在我的控制器中,我有一个 postDispatch 来整合我的 FlashMessenger 消息:
public function postDispatch()
{
$messages = $this->_helper->getHelper ( 'FlashMessenger' )
->getMessages ();
if ( $this->_helper->getHelper ( 'FlashMessenger' )
->hasCurrentMessages () )
{
$messages = array_merge ( $messages, $this->_helper->getHelper ( 'FlashMessenger' )
->getCurrentMessages () );
$this->_helper->getHelper ( 'FlashMessenger' )
->clearCurrentMessages ();
}
$this->view->alert = $messages;
}
我想把它做成一个控制器插件。
更新:我意识到我为什么需要这个 - 我想在 JSON 上下文调用时以 JSON 格式传递我的闪存消息。除非将消息添加到 View 对象,否则我不会收到消息。
我能够将消息放入数组中,但我不知道如何将它们传递给视图:
class Plugin_FlashMessenger extends Zend_Controller_Plugin_Abstract
{
public function postDispatch($request)
{
$flashmessenger = Zend_Controller_Action_HelperBroker::getStaticHelper ( 'FlashMessenger' );
$messages = $flashmessenger->getMessages ();
if ( $flashmessenger->hasCurrentMessages () )
{
$messages = array_merge ( $messages, $flashmessenger->getCurrentMessages () );
$flashmessenger->clearCurrentMessages ();
}
// THIS LINE IS WRONG. HOW DO I SEND $messages TO THE VIEW?
$this->view->alert = $messages;
}
}
奖金问题 - 这是实现这一目标的正确方法吗?谢谢!