我尝试对设置的会话闪存做出反应,但总是得到其他路径
交响乐2.1.3
控制器:
$this->get('session')->getFlashBag()->set('contactActionNoticeError', 'Message not sent');
查看(尝试过“旧”和新风格)但我明白bla2
{% if app.session.flashbag.has("contactActionNoticeError") or app.session.hasFlash("contactActionNoticeError") %}
bla1
{% else %}
bla2
{% endif %}
当显示所有闪烁时:
{% for label, flashes in app.session.flashbag.all %}
{% for flash in flashes %}
{{ label }} - {{ flash }}
{% endfor %}
{% endfor %}
我明白了:
contactActionNoticeError - Message not sent
获取flashbag内容然后查看是否为空:
{% set contactActionNoticeError = app.session.flashbag.get("contactActionNoticeError") %}
{% if (contactActionNoticeError is not empty) %}
bla1
{% else %}
bla2
{% endif %}
您仍然可以显示错误(代码取自文档 http://symfony.com/doc/2.1/book/controller.html#flash-messages):
{% for flashMessage in contactActionNoticeError %}
<div>
{{ flashMessage }}
</div>
{% endfor %}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)