diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 8d4939c277..c86d22f143 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -94,6 +94,7 @@ Yii Framework 2 Change Log - Enh: yii\codeception\TestCase now supports loading and using fixtures via Yii fixture framework (qiangxue) - Enh: Added support to parse json request data to Request::getRestParams() (cebe) - Enh: Added ability to get incoming headers (dizews) +- Enh: Added `beforeRun()` and `afterRun()` to `yii\base\Action` (qiangxue) - Chg #1519: `yii\web\User::loginRequired()` now returns the `Response` object instead of exiting the application (qiangxue) - Chg #1586: `QueryBuilder::buildLikeCondition()` will now escape special characters and use percentage characters by default (qiangxue) - Chg #1610: `Html::activeCheckboxList()` and `Html::activeRadioList()` will submit an empty string if no checkbox/radio is selected (qiangxue) diff --git a/framework/base/Action.php b/framework/base/Action.php index 56b1c45058..ab8083243e 100644 --- a/framework/base/Action.php +++ b/framework/base/Action.php @@ -86,4 +86,23 @@ class Action extends Component } return call_user_func_array([$this, 'run'], $args); } + + /** + * This method is called right before `run()` is executed. + * You may override this method to do preparation work for the action run. + * If the method returns false, it will cancel the action. + * @return boolean whether to run the action. + */ + protected function beforeRun() + { + return true; + } + + /** + * This method is called right after `run()` is executed. + * You may override this method to do post-processing work for the action run. + */ + protected function afterRun() + { + } }