Symfony2 中的 Flash-Messages 似乎在我的 twig-template 中不起作用 [英] Flash-Messages in Symfony2 doesn't seem to work in my twig-template

查看:22
本文介绍了Symfony2 中的 Flash-Messages 似乎在我的 twig-template 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我们的页面上添加对 Flash 消息的支持.我实施了请按照此处的文档进行操作.

I want to add support for flash messages on our pages. I implemented this by following the documentation found here.

我在基本布局中添加了以下代码片段.(我也尝试添加它到一个特定的动作模板).

I added the following snipplet to my base layout. (i also tried to add it to a specific action template).

{% if app.session.hasFlash('notice') %} 
    <div id="flashmessage" class="flash-notice"> 
       {{ app.session.flash('notice') }} 
   </div> 
{% endif %} 

添加后抛出如下错误

Twig_Error_Runtime:第 66 行的MyBundle::layout.html.twig"中不存在"的项目hasFlash"

Twig_Error_Runtime: Item "hasFlash" for "" does not exist in "MyBundle::layout.html.twig" at line 66

我还有什么需要做的吗?

Is there anything else i need to do ?

推荐答案

你用的是symfony 2.0还是2.1 (目前是master分支)?

do you use symfony 2.0 or 2.1 (currently master branch)?

symfony 2.1 的文档位于此处:http://symfony.com/doc/2.1/book/controller.html#flash-messages

for symfony 2.1 the documentation is located here: http://symfony.com/doc/2.1/book/controller.html#flash-messages

flash 消息显示如下:

flash messages are shown like this:

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

这篇关于Symfony2 中的 Flash-Messages 似乎在我的 twig-template 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆