php - Yii2 setFlash not work or lost if redirect

one text

Solution:

In case when you redirect to another action - You have to pass third parameter false. Link to documentation: setFlash()

Yii::$app->session->setFlash('error', 'message text', false);

In other cases, when you want to show the message in the same action you can use it like this:

Yii::$app->session->setFlash('error', 'message text'); // default third parameter is set to true.

Source