sti*_*ink 10 templates symfony twig flash-message
我想在我们的页面上添加对flash消息的支持.我按照此处的文档实现了这一点.
我将以下snipplet添加到我的基本布局中.(我也尝试将其添加到特定的操作模板中).
{% if app.session.hasFlash('notice') %}
<div id="flashmessage" class="flash-notice">
{{ app.session.flash('notice') }}
</div>
{% endif %}
Run Code Online (Sandbox Code Playgroud)
添加以下错误后抛出
Twig_Error_Runtime:第66行"MyBundle :: layout.html.twig"中不存在""的"hasFlash"项
还有什么我需要做的吗?
c33*_*33s 18
你使用symfony 2.0或2.1 (目前是主分公司)?
对于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 }}
</div>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
Mmm检查您的配置文件中是否已自动启动会话:
session:
default_locale: %locale%
auto_start: true
Run Code Online (Sandbox Code Playgroud)
因为错误似乎是Twig找不到会话类,而不是关于hasFlash函数的错误.事实上,我的布局中几乎完全相同的代码.
小智 -1
您是否在操作中的某个位置设置了闪现消息?
$this->get('session')->setFlash('notice', 'Your changes were saved!');
Run Code Online (Sandbox Code Playgroud)
请记住,闪现消息将存储在用户的会话中,以应对一个额外的请求。
归档时间: |
|
查看次数: |
32456 次 |
最近记录: |