backend\controllers\Controller::beforeAction PHP Method

beforeAction() public method

public beforeAction ( Action $action ) : boolean
$action yii\base\Action
return boolean
    public function beforeAction($action)
    {
        if (parent::beforeAction($action)) {
            $uniqueid = $action->controller->action->uniqueid;
            if (!in_array($uniqueid, ['site/login', 'site/logout', 'site/error']) && !User::currUserIsSuperAdmin()) {
                throw new ForbiddenHttpException();
            }
            return true;
        } else {
            return false;
        }
    }

Usage Example

Exemplo n.º 1
0
 /**
  * @param \yii\base\Action $action
  * @return bool
  * @throws \yii\web\BadRequestHttpException
  */
 public function beforeAction($action)
 {
     if (parent::beforeAction($action)) {
         if ($action->id == 'error' && Yii::$app->user->isGuest) {
             $this->layout = 'main-login';
         }
         return true;
     } else {
         return false;
     }
 }