If using MongoDB as session storage, Flash messages do not work.
'session' => [
'name' => 'backend',
'class' => 'yii\mongodb\Session',
'sessionCollection' => 'BackendSessions',
],
/**
* Changing user password
*
* @param string $id User id
* @return mixed
* @throws NotFoundHttpException
*/
public function actionChangePassword($id)
{
$model = User::findOne($id);
if (empty($model)) {
throw new NotFoundHttpException("User specified not found!");
}
$password = User::generateRandomPassword();
$model->setPassword($password);
$model->generateAuthKey();
if ($model->save(false)) {
\Yii::$app->session->setFlash('success', 'New password was set: "'.$password.'"');
} else {
\Yii::$app->session->setFlash('error', 'There was an error changing password!');
}
return $this->redirect(['view', 'id' => $id]);
}
Message is list after redirect. It works if I stop storing sessions in MongoDB.
The problem is here in latest framework version. It works well with 2.0.15.1.
I've translated issue into English so community can participate as a whole.
If the version of MongoDB was not changed, then it seems the problem is somewhere in the framework. Since you have a clear way to reproduce it please do bisect to find out exact commit that broke it. Here's how: https://git-scm.com/docs/git-bisect or in Russian: https://git-scm.com/book/ru/v1/Инструменты-Git-Отладка-с-помощью-Git
This problem after commit:
Class yii\mongodb\Session extends MultiFieldSession
Function MultiFieldSession::composeFields was changed.
If you return the old feature code, it works fine.
@webspec2012 can you check if it's https://github.com/yiisoft/yii2/commit/8bb334b9ae5760f5ad3548f449bf4fe5b9d98d22#r33018458?
The session ID changes from one page to another.
..
db.BackendSessions.remove({});
WriteResult({ "nRemoved" : 4 })
refresh site page by F5
db.BackendSessions.find().pretty();
{
"_id" : ObjectId("5d79f9882893100f3029bfa4"),
"id" : "3racnq6iq3gtm8ma3has4nueva",
"data" : "__flash|a:0:{}__id|s:24:\"5a65db240a64100202b7ca65\";"
}
refresh site page by F5
db.BackendSessions.find().pretty();
{
"_id" : ObjectId("5d79f9882893100f3029bfa4"),
"id" : "04gl55gs0ecj22q61tu3s9l475",
"data" : "__flash|a:0:{}__id|s:24:\"5a65db240a64100202b7ca65\";"
}
refresh site page by F5
db.BackendSessions.find().pretty();
{
"_id" : ObjectId("5d79f9882893100f3029bfa4"),
"id" : "ilcs8pkjetisbie47p0h524adb",
"data" : "__flash|a:0:{}__id|s:24:\"5a65db240a64100202b7ca65\";"
}
...
Does PHP write it into MongoDB at all?

This log for each page..
@lubosdz any idea on why would it break?
my 2 cents, this looks sketchy - I would start investigating that:
https://github.com/yiisoft/yii2/blob/8bb334b9ae5760f5ad3548f449bf4fe5b9d98d22/framework/web/DbSession.php#L194
@ailmanki thanks, that would be awesome.
Mongodb Session class not extends DbSession.
Mongodb Session class not extends DbSession.
So is the issue solved ?
I reckon yii2-mongo sessionWrite has not been updated accordingly after bugfix - compare:
https://github.com/yiisoft/yii2-mongodb/blob/master/src/Session.php#L137
https://github.com/yiisoft/yii2/blob/master/framework/web/DbSession.php#L186
Unfortunatelly I dont have mongo setup ..
Edit:
Related mongo issue #279 - see e.g. failing build.
So is the issue solved ?
No.
@webspec2012 can you test with dev-master of the yiisoft/yii2-mongo?
The `dev-master ' branch works correctly!
Most helpful comment
Mongodb Session class not extends DbSession.