skip to Main Content

I wrote a controller in Shopware 6 (symfony based) that adds a flash messages via $this->addFlash(...).

As expected the message is shown in the storefront (product detail page).

In the function SymfonyComponentHttpFoundationSessionFlashFlashBag::all the message is removed as expected (checked via xdebug).

But when I refresh, the flash message is shown again and is also contained in the session.

I also checked this directly in the PHP session:

$_SESSION['_symfony_flashes']

The message is correctly removed there, but reappears on the next page load.

The only idea I have is, that the session is not persisted after the flash message is removed from it. But I never faced such behavior in the Symfony sessions or PHP sessions.

What could be the reason for this?

2

Answers


  1. My best guess is that the page is cached with the flash message intact. Afaik flash messages are primarily used on routes that are exempt from caching. The product detail page is not one of those by default. You might have to enrich the cache key for the page by a parameter denoting whether the flash message should be shown or not.

    Login or Signup to reply.
  2. Adding to dneustadt’s answer: As the product detail page is cached, also your flash message will not show if the detail page is generated and cached without the addFlash() and later your condition for the addFlash() becomes true: Then your controller will just not be hit and the cached page without the flash message will be shown.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search