我想在我们的页面上添加对即时消息的支持。我实现了 通过遵循文档发现 here .
我将以下代码片段添加到我的基本布局中。 (我也尝试添加 它到特定的操作模板)。
{% if app.session.hasFlash('notice') %}
<div id="flashmessage" class="flash-notice">
{{ app.session.flash('notice') }}
</div>
{% endif %}
添加后抛出以下错误
Twig_Error_Runtime: Item "hasFlash" for "" does not exist in "MyBundle::layout.html.twig" at line 66
还有什么我需要做的吗?
最佳答案
你使用symfony 2.0还是2.1(当前是master分支)?
对于 symfony 2.1,文档位于此处:http://symfony.com/doc/2.1/book/controller.html#flash-messages
闪现消息显示如下:
{% for flashMessage in app.session.flashbag.get('notice') %}
<div class="flash-notice">
{{ flashMessage }}
</div>
{% endfor %}
关于templates - Symfony2 中的 Flash 消息似乎在我的 twig-template 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8240110/