Commit 49010df1 by Qiang Xue

Changed `Controller::afterAction()`, `Module::afterAction()` and…

Changed `Controller::afterAction()`, `Module::afterAction()` and `ActionFilter::afterAction()` to pass `$result` by value instead of reference
parent 48926fa6
......@@ -205,7 +205,7 @@ Yii Framework 2 Change Log
- Renamed `yii\web\User::authTimeoutVar` to `authTimeoutParam`
- Renamed `yii\web\User::returnUrlVar` to `returnUrlParam`
- Chg: Added `View::viewFile` and removed `ViewEvent::viewFile` (qiangxue)
- Chg: Changed `Controller::afterAction()`, `Module::afterAction()` and `ActionFilter::afterAction()` to pass `$result` by value instead of reference (qiangxue)
- New #66: [Auth client library](https://github.com/yiisoft/yii2-authclient) OpenId, OAuth1, OAuth2 clients (klimov-paul)
- New #706: Added `yii\widgets\Pjax` and enhanced `GridView` to work with `Pjax` to support AJAX-update (qiangxue)
- New #1393: [Codeception testing framework integration](https://github.com/yiisoft/yii2-codeception) (Ragazzo)
......
......@@ -65,7 +65,7 @@ class ActionFilter extends Behavior
public function afterFilter($event)
{
if ($this->isActive($event->action)) {
$this->afterAction($event->action, $event->result);
$event->result = $this->afterAction($event->action, $event->result);
}
}
......@@ -85,9 +85,11 @@ class ActionFilter extends Behavior
* You may override this method to do some postprocessing for the action.
* @param Action $action the action just executed.
* @param mixed $result the action execution result
* @return mixed the processed action result.
*/
public function afterAction($action, &$result)
public function afterAction($action, $result)
{
return $result;
}
/**
......
......@@ -126,11 +126,12 @@ class Controller extends Component implements ViewContextInterface
Yii::$app->trigger(Application::EVENT_BEFORE_ACTION, $event);
if ($event->isValid && $this->module->beforeAction($action) && $this->beforeAction($action)) {
$result = $action->runWithParams($params);
$this->afterAction($action, $result);
$this->module->afterAction($action, $result);
$result = $this->afterAction($action, $result);
$result = $this->module->afterAction($action, $result);
$event = new ActionEvent($action);
$event->result = &$result;
$event->result = $result;
Yii::$app->trigger(Application::EVENT_AFTER_ACTION, $event);
$result = $event->result;
}
$this->action = $oldAction;
return $result;
......@@ -222,14 +223,17 @@ class Controller extends Component implements ViewContextInterface
* This method is invoked right after an action is executed.
* You may override this method to do some postprocessing for the action.
* If you override this method, please make sure you call the parent implementation first.
* Also make sure you return the action result, whether it is processed or not.
* @param Action $action the action just executed.
* @param mixed $result the action return result.
* @return mixed the processed action result.
*/
public function afterAction($action, &$result)
public function afterAction($action, $result)
{
$event = new ActionEvent($action);
$event->result = &$result;
$event->result = $result;
$this->trigger(self::EVENT_AFTER_ACTION, $event);
return $event->result;
}
/**
......
......@@ -658,10 +658,13 @@ class Module extends Component
* This method is invoked right after an action of this module has been executed.
* You may override this method to do some postprocessing for the action.
* Make sure you call the parent implementation so that the relevant event is triggered.
* Also make sure you return the action result, whether it is processed or not.
* @param Action $action the action just executed.
* @param mixed $result the action return result.
* @return mixed the processed action result.
*/
public function afterAction($action, &$result)
public function afterAction($action, $result)
{
return $result;
}
}
......@@ -136,15 +136,12 @@ class PageCache extends ActionFilter
}
/**
* This method is invoked right after an action is executed.
* You may override this method to do some postprocessing for the action.
* @param Action $action the action just executed.
* @param mixed $result the action execution result
* @inheritdoc
*/
public function afterAction($action, &$result)
public function afterAction($action, $result)
{
echo $result;
$this->view->endCache();
$result = ob_get_clean();
return ob_get_clean();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment