Search code examples
symfonysymfony-2.6

How to set symfony2 flash message in diferente Aplication Context?


I have an application with Frontend(sales) and Backend(administration), what I want to do is to set the flash messages separated by context, because When I'm login in both context I'm received in the Backend messages that belong to the Frontend, and I don't want it.

Sorry about my English but I'm not an English speaker. King Regards


Solution

  • If you are using the sessions flash bag then you just need to use different names when adding a message. For example you could use the following for admin messages:

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

    Then do the same thing in your public controllers/templates but replace 'admin_error' with something like 'public_error'.