Answer the question
In order to leave comments, you need to log in
How does yii2 session store if DbSession is not connected?
Hello! I am doing my first project on yii2, the site has authorization and a "remember" function that saves authorization for 30 days. To make remember-me work, I added functions from IdentityInterface to the user model (which extends ActiveRecord implements IdentityInterface):
public static function findIdentity($id)
{
return self::findOne($id);
}
public function getId()
{
return $this->User_ID;
}
public static function findIdentityByAccessToken($token, $type = null)
{
return static::findOne(['access_token' => $token]);
}
public function getAuthKey()
{
return $this->authKey;
}
public function validateAuthKey($authKey)
{
return $this->authKey === $authKey;
}
Yii::$app->user->login($login_model->getUser(),$login_model->rememberMe());
// Где rememberMe :
public function rememberMe()
{
return $this->rememberMe ? 3600*24*30 : 0;
}
// из модели login
Answer the question
In order to leave comments, you need to log in
in the standard configuration, yii2 stores the session in files, but you should understand that the "remember" function works not through the session, but through the cookie. Those. when authorizing, an encrypted cookie with an authentication key is set to the user, and when the user revisits the site, it occurs in existing users.
The storage for sessions is naturally configurable. More details about working with sessions in yii are written here
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question