如何在不同的应用程序上下文中设置 symfony flash 消息?

How to set symfony2 flash message in diferente Aplication Context?

我有一个带有前端(销售)和后端(管理)的应用程序,我想做的是设置由上下文分隔的闪存消息,因为当我在这两个上下文中登录时,我收到了属于前端的后端消息,我不要。

抱歉我的英语不好,但我不会说英语。 国王问候

如果您使用的是 sessions flash 包,那么您只需要在添加消息时使用不同的名称即可。例如,您可以将以下内容用于管理员消息:

// in your controller
$this->get('session')->getFlashBag()
  ->add('admin_error','No user found with that email address');

.........................................................

{# in your template #}
{% for flashMessage in app.session.flashbag.get('admin_error') %}
  <div class="error-message">{{ flashMessage }}</div>
{% endfor %}

然后在 public controllers/templates 中做同样的事情,但将 'admin_error' 替换为 'public_error'.