yii\web\User::getIsGuest PHP Метод

getIsGuest() публичный Метод

Returns a value indicating whether the user is a guest (not authenticated).
См. также: getIdentity()
public getIsGuest ( ) : boolean
Результат boolean whether the current user is a guest.
    public function getIsGuest()
    {
        return $this->getIdentity() === null;
    }

Usage Example

Пример #1
0
 /**
  * check the permission, if we rewrite and controller, the controller id and module id is not changed
  * @param \yii\base\Action $action
  * @param \yii\web\User $user
  * @param \yii\web\Request $request
  * @return bool
  */
 public function matchActionAccess($action, $user, $request)
 {
     if ($user->getIsGuest()) {
         return false;
     }
     /** @var \core\auth\Module $authModule */
     $authModule = \Yii::$app->getModule('core_auth');
     foreach ($authModule->getAdmins() as $key => $admin) {
         if ($user->getIdentity()->username == $admin['username']) {
             return true;
         }
     }
     if ($action->controller->module instanceof Application) {
         $key = 'default' . '_' . $action->controller->id . '_' . $action->id;
     } else {
         $key = $action->getUniqueId();
         $key = explode('/', $key);
         array_shift($key);
         $key = implode('_', $key);
     }
     $key = lcfirst(implode('', array_map(function ($k) {
         return ucfirst($k);
     }, explode('-', $key))));
     return $user->can($key, $this->params);
 }
All Usage Examples Of yii\web\User::getIsGuest