简体   繁体   English

Symfony 2.8.2 flashmessage和redirecttoroute

[英]Symfony 2.8.2 flashmessage and redirecttoroute

I'm using Symfony 2.8.2 and somehow the FlashMessage does not live through a redirect. 我正在使用Symfony 2.8.2,并且FlashMessage不能通过重定向生存。

$this->addFlash('success', 'Expedition erfolgreich!');
return $this->redirectToRoute('mainmenu_dashboard');

After the redirect there is no flashmessage. 重定向之后,没有flashmessage。 I already looked in the session (dumped it) but there is no flash message after the redirect. 我已经在会话中查找(转储了),但重定向后没有刷新消息。

Any ideas? 有任何想法吗?

You'll need to check for, and display, the flashMessage in your twig template for the mainmenu_dashboard route. 您需要在树枝模板中为mainmenu_dashboard路线检查并显示flashMessage。

For example: 例如:

{% for flashMessage in app.session.flashbag.get('success') %}
    <div class="success">{{ flashMessage }}</div>
{% endfor %}

The flash will exist in session, between routes, until they are used. 闪存将在会话之间,路由之间存在,直到被使用。

Symfony Doc Symfony文档

Thank's for your answer! 感谢您的回答!

I discovered the problem somewhere else. 我在其他地方发现了问题。 I used session_write_close() somewhere else to set the session to not blocking (to be able to cancel a request). 我在其他地方使用session_write_close()将会话设置为不阻塞(以便取消请求)。 This was the reason why session was not writeable at this point anymore! 这就是为什么会话此时不再可写的原因!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM