twitter-bootstrap - 在 Flash 消息 symfony2 中添加模板

标签 twitter-bootstrap symfony

在创建和删除对象之后,我重定向到相同的操作(indexAction)。
创建后,我想将此 Bootstrap 消息呈现为闪存消息:

<div class="alert alert-success" role="alert">
  <a href="#" class="alert-link">...</a>
</div>

但删除后,我想渲染另一个html block :
<div class="alert alert-danger" role="alert">
  <a href="#" class="alert-link">...</a>
</div>

将其传递给 Flash 消息的最佳方法是什么?
因为,我认为传递所有 html 不是好主意?
$this->get('session')->getFlashBag()->add(
        'notice',
        '<div class="alert alert-danger" role="alert">
             <a href="#" class="alert-link">...</a>
         </div>'
    );

有没有更好的方法来解决这个问题?

最佳答案

这是我通常做的:

{% for type, flashes in app.session.flashbag.all %}
    {% for flash in flashes %}
        <div class="alert alert-{{ type }} fade in">
            {{ flash }}
        </div>
    {% endfor %}
{% endfor %}
来自 Controller :
$this->addFlash('success', 'What an awesome message !');
将创建一个 alert-success

关于twitter-bootstrap - 在 Flash 消息 symfony2 中添加模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25212973/

相关文章:

javascript - 无法创建由 AngularJs 注入(inject)的 Bootstrap 轮播

html - 小屏幕的 View 重叠

php - 在 FOSUserBundle 中,如何创建替代注销

php - Doctrine 2.1.5 setFirstResult() 在 MySQL 5.5 中产生错误

npm - 如何在 Symfony 的 View 中引用 node_modules 组件

javascript - 文档边栏中的元素不会自动激活

javascript - 单击菜单导航动画到该部分

css - 如何使用 SASS 或 CSS3 将 !important 放在所有 CSS 属性中?

php - 一个实体的多个 OneToMany 关系

php - 未找到 Symfony 类