Setting Flash in on event

I’m trying to add flash message on event hapenning.

I’ve checked - function is calling, but if I’m setting session flash messages - they aren’t appearing after redirect.

What am I doing wrong and how to solve it?




'signup' => [

    'class' => 'nord\yii\account\controllers\SignupController',

    'on afterActivation' => function ($event) {

        \Yii::$app->session->setFlash('success', 'Account has been successfully activated!');

    }

]

Bump me up again, please!

How are you reading the message?

This way:




<?php

foreach(Yii::$app->session->getAllFlashes() as $key => $message) {

    echo '<div class="alert alert-' . $key . '">' . $message . '</div>';

} ?>



I’ve checked if they are exist right after setting, and the are, but not after redirect.

That’s weird. Try starting session explicitly by Yii::$app->session->open().

Sorry for long no anwer. I’ve rechecked, flashes aren’t working for me at all. Even in this case they aren’t working.


public function actionFirst()

{

    Yii::$app->session->open();

    Yii::$app->session->setFlash('success', 'test');

    return $this->redirect('second');

}


public function actionSecond()

{

    Yii::$app->session->open();

    $flashes = Yii::$app->session->getAllFlashes();

    var_dump($flashes);

}

I should recheck all my configuration then.

Added in components section:


'session' => [

    'class' => 'yii\web\CacheSession',

],

Now flashes are working, just wondering why Yii weren’t raising an error that sessions couldn’t be written.

Thats my first basic application. On advanced applications webserver config files are same and all working good from a stock. I’ve checked session directory, it is writable, but session files aren’t created. What could it be?

I’ve tried to fallback to default user component:




'user' => [

    'identityClass' => 'common\models\User',

    'enableAutoLogin' => true,

    'enableSession' => true,

],