Yes it does work when logout() method is removed. Any idea on how to implement it to work with the logout() method? Is this the expected behaviour? I am not sure on what technology is being used behind the flash messages but if it uses sessions, which most likely it does, than possibility to achieve it with flashes is zero…
Yes it uses session. I don’t know easy solution. logout(false) doesn’t work I guess since the flash message is set internally via setState(). Also I don’t understand why there is no new session created when calling setFlash() after logout().
// As a workaround try defining another WebUser in config. Then use that for flashMessages only (eg Yii::app()->dummyUser->setFlash). Maybe that works.
After talking with bettor via private message, it’s clear now that logout(false) works. The reason is that logout() destroys whole session, so it’s not possible to set anything to the session afterwards. With logout(false), only user relevant data get’s destroyed, not the session itself. This should work as well I guess:
Just want to let you now that this works. If you need to destroy a whole session but you want to set a flash afterwards, you may extends CWebUser this way:
<?php
class BaseWebUser extends CWebUser
{
public function logout($destroySession = true)
{
parent::logout($destroySession);
Yii::app()->session->open();
}
}
?>