yii\web\User::logout PHP Method

logout() public method

This will remove authentication-related session data. If $destroySession is true, all session data will be removed.
public logout ( boolean $destroySession = true ) : boolean
$destroySession boolean whether to destroy the whole session. Defaults to true. This parameter is ignored if [[enableSession]] is false.
return boolean whether the user is logged out
    public function logout($destroySession = true)
    {
        $identity = $this->getIdentity();
        if ($identity !== null && $this->beforeLogout($identity)) {
            $this->switchIdentity(null);
            $id = $identity->getId();
            $ip = Yii::$app->getRequest()->getUserIP();
            Yii::info("User '{$id}' logged out from {$ip}.", __METHOD__);
            if ($destroySession && $this->enableSession) {
                Yii::$app->getSession()->destroy();
            }
            $this->afterLogout($identity);
        }
        return $this->getIsGuest();
    }

Usage Example

コード例 #1
0
ファイル: User.php プロジェクト: hughcube/yii2-web
 public function logout($destroySession = true)
 {
     if (!$this->getIsGuest()) {
         /** @type IdentityAuthTrait $identity */
         $identity = $this->getIdentity();
         return $identity->deleteToken($this->tokenType);
     }
     return parent::logout($destroySession);
 }