yii\web\User::setIdentity PHP Method

setIdentity() public method

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)
    {
        if ($identity instanceof IdentityInterface) {
            $this->_identity = $identity;
            $this->_access = [];
        } elseif ($identity === null) {
            $this->_identity = null;
        } else {
            throw new InvalidValueException('The identity object must implement IdentityInterface.');
        }
    }

Usage Example

Exemplo n.º 1
0
 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;
       }*/
 }
All Usage Examples Of yii\web\User::setIdentity