Note that this method does not deal with session or cookie. You should usually use User::switchIdentity
to change the identity of the current user.
public setIdentity ( yii\web\IdentityInterface | null $identity ) | ||
$identity | yii\web\IdentityInterface | null | the identity object associated with the currently logged user. If null, it means the current user will be a guest without any associated identity. |
public function setIdentity($identity) { // Allows use in console if (!\Yii::$app->hasProperty('request')) { $this->_overrideIdentity = $identity; } else { parent::setIdentity($identity); } // @todo Wrong place for update app config, it's code running only on call user component. // Configure localization /*if (!\Yii::$app->user->isGuest) { \Yii::$app->formatter->locale = \Yii::$app->user->model->locale; \Yii::$app->formatter->timeZone = \Yii::$app->user->model->timeZone; }*/ // Expose detail exceptions to support accounts always /*if ($identity && $identity->getId() === USER_EXTPOINT_SUPPORT) { Yii::$app->errorHandler->errorView = Yii::$app->errorHandler->exceptionView; }*/ }
/** * * overwrite 存到session */ public function setIdentity($identity) { parent::setIdentity($identity); Yii::$app->session["_userInfo"] = $identity; }