dor*_*aji 3 action zend-framework helper flash-message
所以我正在使用zend-framwork创建一个项目,我正在尝试实现flash messenger助手,但我找不到任何好的实践来实现它.我需要的是使用flash messenger发送消息和重定向,而消息将直接出现在layout.phtml中的特定位置.我知道,对于重定向器,我可以这样做:
$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
$redirector->gotoUrl('/my-controller/my-action/param1/test/param2/test2')
->redirectAndExit();'
Run Code Online (Sandbox Code Playgroud)
我可以对闪光灯消息器做些什么来使其工作?那是什么最好的做法?
在你的控制器中
public function init()
{
$messages = $this->_helper->flashMessenger->getMessages();
if(!empty($messages))
$this->_helper->layout->getView()->message = $messages[0];
}
Run Code Online (Sandbox Code Playgroud)
在你的layout.phtml中
<!-- Global notification handling to use call flashMessenger action helper -->
<?php if(isset($this->message)) :?>
<div class="notification">
<?php echo $this->message ;?>
</div>
<?php endif;?>
Run Code Online (Sandbox Code Playgroud)
然后每当你想使用它
public function loginAction()
{
$this->_helper->flashMessenger('Login is success');
$this->_helper->redirector('home');
}
Run Code Online (Sandbox Code Playgroud)
在使用flashMessenger之后,您几乎每次都会重定向.
| 归档时间: |
|
| 查看次数: |
10706 次 |
| 最近记录: |