本文整理汇总了PHP中yii\base\Module::afterAction方法的典型用法代码示例。如果您正苦于以下问题:PHP Module::afterAction方法的具体用法?PHP Module::afterAction怎么用?PHP Module::afterAction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\base\Module
的用法示例。
在下文中一共展示了Module::afterAction方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: runAction
/**
* 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: afterAction
/**
* 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;
}