A way to store flash messages besides CwebUser

The current way stores the flash messages in the CWebUser lib which is erased when being logged out as it seems. So if I want to store a flash message like “you have been successfully logged out” and redirect the user to the logout page the message is erased during logout so my question is…wouldn’t it make more sense to keep the flash messages outside that class and make it available no matter what action is being performed regarding user? Or is there another way of storing flash messages that I’m missing?

In Web3CMS I did following:


    /**

     * Logout the current user and redirect to homepage.

     */

    public function actionLogout()

    {

        $isLoggedIn=!Yii::app()->user->isGuest;

        $screenName=$isLoggedIn ? Yii::app()->user->screenName : '';

        // log user out and destroy all session data

        Yii::app()->user->logout();

        // if user was logged in, we should notify of being logged out

        if($isLoggedIn)

        {

            if(!Yii::app()->getSession()->getIsStarted())

                // have to re-open session destroyed on logout. this is necessary for user flash

                Yii::app()->getSession()->open();

            // set the goodbye message

            MUserFlash::setTopInfo(Yii::t('feedback',

                '{screenName}, you have been successfully logged out.',

                array('{screenName}'=>'<strong>'.$screenName.'</strong>')

            ));

        }

        // go to home page

        $this->redirect(Yii::app()->homeUrl);

    }

so, you have to open the session again before assigning a flash message Yii::app()->getSession()->open();

You may use Yii::app()->user->logout(false), i.e., do not destroy session when logout.

That worked. Thanks.

Hmm, I still can’t get it to work. I want to do the exact same thing.




public function actionLogout() {

Yii::app()->user->logout(false);

Yii::app()->user->setFlash('flashMsg', 'You have been logged out.');

$this->redirect(Yii::app()->homeUrl);

}



Thoughts?