Mil*_*loš 8 php controller symfony twig flash-message
我在渲染树枝模板时在控制器中设置了一条flash消息.如果有帖子操作,我想重定向到同一页面,但更改Flash消息.
if ($request->isMethod('POST')) {
...
...
$this->get('session')->getFlashBag()->clear(); // Does not work
$this->get('session')->getFlashBag()->all(); // Does not work
$request->getSession()->getFlashBag()->set('user-notice', $flash_message2);
return $this->redirect($request->headers->get('referer'));
}
$this->get('session')->getFlashBag()->set('user-notice', $flash_message1);
return $this->render(....
Run Code Online (Sandbox Code Playgroud)
但问题是显示的flash消息是$ flash_message1,应该是$ flash_message2.
当尝试使用add而不是set时,我可以看到它们.我试图使用Symfony2 clear()
和all()
函数:http://api.symfony.com/2.3/Symfony/Component/HttpFoundation/Session/Flash/FlashBagInterface.html 但没有任何改变.
任何的想法?谢谢 !!!
Nic*_*ich 13
使用...
$flashBag = $this->get('session')->getFlashBag();
$flashBag->get('user-notice'); // gets message and clears type
$flashBag->set('user-notice', $flash_message2);
Run Code Online (Sandbox Code Playgroud)
......在你的isPost()
病情之后.
小智 13
要清除所有Flash消息,请使用以下代码:
$this->get('session')->getFlashBag()->clear();
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
12934 次 |
最近记录: |