Symfony2 FlashBag 在升级到 2.4 后停止工作? [英] Symfony2 FlashBag stopped working after upgrade to 2.4?
问题描述
在我的控制器中,我使用此代码添加了一条闪现消息并重定向:
$this->get('session')->getFlashBag()->add('success', 'Foo Message');返回 $this->redirect($this->generateUrl('list_route'));
我使用以下代码在模板中显示消息:
{% for type, flashMessages in app.session.flashbag.all() %}{% 用于 flashMessages 中的 flashMessage %}<div class="alert alert-{{ type }}"><button type="button" class="close" data-dismiss="alert">×</button>{{ flashMessage|raw }}{% 结束为 %}{% 结束为 %}
在我从 symfony 2.3 升级到 2.4.1 之前,这非常有效.
没有错误,我的日志中没有错误.该消息根本不显示,app.session.flashbag
为空.
闪包有什么变化吗?如何解决?
您是否偶然使用了 Liip\CacheControlBundle
?我遇到了完全相同的问题,经过一番挖掘,我发现这个捆绑包可以清除闪存包.
在 config.yml
中查看是否有 flash_message_listner: true
行,如果有的话把它转为 false
并且事情应该再次工作.
我这样做是为了回答,因为我没有足够的代表来发表评论.我想 Liip\CacheControlBundle
也会在以前的版本中做到这一点,但我想我会试一试,因为它对我有用.
我没有得到标准的分发包,而是得到了 REST 分发包,它带有这个包,默认情况下包含 flash_message_listner: true
.简单地翻转它,解决了我的问题.
In my controller I used this code to add a flash-message and redirect:
$this->get('session')->getFlashBag()->add('success', 'Foo Message');
return $this->redirect($this->generateUrl('list_route'));
I displayed the messages in the template with this code:
<div id="flashes" class="row-fluid">
{% for type, flashMessages in app.session.flashbag.all() %}
{% for flashMessage in flashMessages %}
<div class="alert alert-{{ type }}">
<button type="button" class="close" data-dismiss="alert">×</button>
{{ flashMessage|raw }}
</div>
{% endfor %}
{% endfor %}
</div>
This worked perfectly until I upgraded from symfony 2.3 to 2.4.1.
There is no error, nothing wrong in my logs. The message is simply not displayed, app.session.flashbag
is empty.
Did something change with the flashbag? How to fix that?
Are you using the Liip\CacheControlBundle
by chance? I had the exact same problem and after some digging I found out that this bundle clears the flashbag.
in config.yml
see if there is a flash_message_listner: true
line and if there is turn it to false
and things should work again.
I did this as an answer because I don't have enough rep to comment. I imagine that Liip\CacheControlBundle
would have done that in the previous version too, but I thought I would give it a shot because it worked for me.
Instead of getting the standard distribution bundle I got the REST distribution and it came with this package which includes that flash_message_listner: true
by default. Simply flipping that, fixed my problem.
这篇关于Symfony2 FlashBag 在升级到 2.4 后停止工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!