beforeAction() public method

The method will trigger the [[EVENT_BEFORE_ACTION]] event. The return value of the method will determine whether the action should continue to run. In case the action should not run, the request should be handled inside of the beforeAction code by either providing the necessary output or redirecting the request. Otherwise the response will be empty. If you override this method, your code should look like the following: php public function beforeAction($action) { your custom code here, if you want the code to run before action filters, which are triggered on the [[EVENT_BEFORE_ACTION]] event, e.g. PageCache or AccessControl if (!parent::beforeAction($action)) { return false; } other custom code here return true; // or false to not run the action }
public beforeAction ( Action $action ) : boolean
$action Action the action to be executed.
return boolean whether the action should continue to run.
Beispiel #1
0
 function beforeAction($event)
 {
     $this->model_name = ucfirst($_GET['model']);
     $this->model_class_name = "app\\models\\" . $this->model_name;
     Yii::$app->response->format = 'json';
     return parent::beforeAction($event);
 }
 /**
  * @inheritdoc
  */
 public function beforeAction($action)
 {
     if (parent::beforeAction($action)) {
         if ($this->enableCsrfValidation && Yii::$app->exception === null && !Yii::$app->getRequest()->validateCsrfToken()) {
             throw new BadRequestHttpException(Yii::t('yii', 'Unable to verify your data submission.'));
         }
         return true;
     } else {
         return false;
     }
 }
 public function beforeAction($action)
 {
     Yii::$app->response->format = 'json';
     return parent::beforeAction($action);
 }