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

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

问题描述

我想在我们的页面上添加对 Flash 消息的支持.我实现了这是按照在此处找到的文档进行的.

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

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

{% 万一 %}

添加后抛出以下错误

<块引用>

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

还有什么我需要做的吗?

解决方案

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

对于 symfony 2.1,文档位于:http://symfony.com/doc/2.1/book/controller.html#flash-messages

Flash 消息显示如下:

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

{% 结束为 %}

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 %} 

After adding the following error is thrown

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 ?

解决方案

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

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

flash messages are shown like this:

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

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

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆