Flash Message with warning,success, info and danger automatically shown

I’m discovering Yii2 every day but hit something strange by trying to manage Flash messages I was not seeing them in my session after setting a single flash at the end of my logging as:
$session->setFlash(‘success’, ‘Success’);
So I tried the following in my site controller to check the session:
public function actionIndex()
{
$session = Yii::$app->session;
$session->set(‘language’, ‘fr-FR’);
$session->setFlash(‘Flash01’, ‘01’);
$session->setFlash(‘warning’, ‘Warning’);
$session->setFlash(‘success’, ‘Success’);
$session->setFlash(‘danger’, ‘Danger’);
$session->setFlash(‘info’, ‘Info’);
return $this->render(‘index’);
}
And I discover that I was not seeing in the session the warning,success,danger,info because they were already “consumed” and this without any getFlash or AlertWidget but flash ‘Flash01’ is correctly ready in the session.
Am I missing a point or is it really an oddity…
image
image

The flash messages are being consumed, probably by the Alert widget.

It works like this:

  1. When you set Flash, it will insert it on the session var
  2. The Alert widget is called, it will get and remove alert messages from session and print on HTML.

What are you trying to achieve with this?

Oh, and the Alert widget is usually called on views/layouts/main.php

You are right, but as I used the layout provided I didn’t notice it was using the Alert widget. I knew this was consuminf the flash message but as I was sure to never wrote <?= Alert::widget() ?> in my code I event didn’t think to make a general search on my src.
My bad…
Thanks