yii2 - How to change the behavior of the beforeAction? -


there beforeaction() in controller.php

public function beforeaction($action)     {         if (parent::beforeaction($action)) {             if ($this->enablecsrfvalidation && yii::$app->geterrorhandler()->exception === null && !yii::$app->getrequest()->validatecsrftoken()) {                 throw new badrequesthttpexception(yii::t('yii', 'unable verify data submission.'));             }             return true;         }          return false;     } 

it throws exception want change in own controller extends controller.php. try that

public function beforeaction($action) {     if ($this->enablecsrfvalidation && yii::$app->geterrorhandler()->exception === null && !yii::$app->getrequest()->validatecsrftoken()) {         yii::$app->session->setflash('info', 'error');         $this->goback();     }     return parent::beforeaction($action); } 

but still shows exception.

not sure might work changing row...

$this->goback(); 

into...

return $this->goback(); 

another approach catch exception parent instead. later there might other events triggered beforeaction , if not calling parent::beforeaction these may not run intended.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -