Setting flash message with $this->Flash is not working - help please

I think what might be happening is that it displays the flash (thus clearing it from the session) and then redirects the user again.
It happened to me a while ago as well.
Please check how your app redirects your browser (this can be done using the network monitor of your browser).

What happens in CakePHP is:

  • $this->Flash->error(): Add an object to the array of "unrendered" flashes (in the session), telling CakePHP that this flash hasn't been rendered yet
  • $this->Flash->render(): Loop through the array of "unrendered" flashes, remove the object from the array and display the flash

You can see the function that renders the flash here: https://api.cakephp.org/3.3/source-class-Cake.View.Helper.FlashHelper.html#29-93