afterAction() публичный Метод

The method will trigger the [[EVENT_AFTER_ACTION]] event. The return value of the method will be used as the action return value. If you override this method, your code should look like the following: php public function afterAction($action, $result) { $result = parent::afterAction($action, $result); your custom code here return $result; }
public afterAction ( Action $action, mixed $result ) : mixed
$action Action the action just executed.
$result mixed the action return result.
Результат mixed the processed action result.
 /**
  * Runs an action within this controller with the specified action ID and parameters.
  * If the action ID is empty, the method will use [[defaultAction]].
  * @param string $id the ID of the action to be executed.
  * @param array $params the parameters (name-value pairs) to be passed to the action.
  * @return mixed the result of the action.
  * @throws InvalidRouteException if the requested action ID cannot be resolved into an action successfully.
  * @see createAction()
  */
 public function runAction($id, $params = [])
 {
     $action = $this->createAction($id);
     if ($action !== null) {
         Yii::trace("Route to run: " . $action->getUniqueId(), __METHOD__);
         if (Yii::$app->requestedAction === null) {
             Yii::$app->requestedAction = $action;
         }
         $oldAction = $this->action;
         $this->action = $action;
         $result = null;
         $event = new ActionEvent($action);
         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);
             $event = new ActionEvent($action);
             $event->result =& $result;
             Yii::$app->trigger(Application::EVENT_AFTER_ACTION, $event);
         }
         $this->action = $oldAction;
         return $result;
     } else {
         throw new InvalidRouteException('Unable to resolve the request: ' . $this->getUniqueId() . '/' . $id);
     }
 }
Пример #2
0
 /**
  * Registers user activity after every action.
  * @see \bizley\podium\models\Activity
  * 
  * @param \yii\base\Action $action the action just executed.
  * @param mixed $result the action return result.
  * @return mixed the processed action result.
  */
 public function afterAction($action, $result)
 {
     $parentResult = parent::afterAction($action, $result);
     if (Yii::$app instanceof WebApplication && !in_array($action->id, ['import', 'run'])) {
         Activity::add();
     }
     return $parentResult;
 }