yii\filters\auth\AuthMethod::beforeAction PHP Method

beforeAction() public method

public beforeAction ( $action )
    public function beforeAction($action)
    {
        $response = $this->response ?: Yii::$app->getResponse();
        try {
            $identity = $this->authenticate($this->user ?: Yii::$app->getUser(), $this->request ?: Yii::$app->getRequest(), $response);
        } catch (UnauthorizedHttpException $e) {
            if ($this->isOptional($action)) {
                return true;
            }
            throw $e;
        }
        if ($identity !== null || $this->isOptional($action)) {
            return true;
        } else {
            $this->challenge($response);
            $this->handleFailure($response);
            return false;
        }
    }

Usage Example

Example #1
0
 /**
  * @inheritdoc
  */
 public function beforeAction($action)
 {
     return empty($this->authMethods) ? true : parent::beforeAction($action);
 }