yii\base\Controller::runAction PHP Method

runAction() public method

If the action ID is empty, the method will use [[defaultAction]].
See also: createAction()
public runAction ( string $id, array $params = [] ) : mixed
$id string the ID of the action to be executed.
$params array the parameters (name-value pairs) to be passed to the action.
return mixed the result of the action.
    public function runAction($id, $params = [])
    {
        $action = $this->createAction($id);
        if ($action === null) {
            throw new InvalidRouteException('Unable to resolve the request: ' . $this->getUniqueId() . '/' . $id);
        }
        Yii::trace('Route to run: ' . $action->getUniqueId(), __METHOD__);
        if (Yii::$app->requestedAction === null) {
            Yii::$app->requestedAction = $action;
        }
        $oldAction = $this->action;
        $this->action = $action;
        $modules = [];
        $runAction = true;
        // call beforeAction on modules
        foreach ($this->getModules() as $module) {
            if ($module->beforeAction($action)) {
                array_unshift($modules, $module);
            } else {
                $runAction = false;
                break;
            }
        }
        $result = null;
        if ($runAction && $this->beforeAction($action)) {
            // run the action
            $result = $action->runWithParams($params);
            $result = $this->afterAction($action, $result);
            // call afterAction on modules
            foreach ($modules as $module) {
                /* @var $module Module */
                $result = $module->afterAction($action, $result);
            }
        }
        $this->action = $oldAction;
        return $result;
    }

Usage Example

Beispiel #1
0
 public function runAction($id, $params = [])
 {
     // Skip \yii\console\Controller::runAction impl.
     // Don't care about options and arguments. Just pass the call through
     // to Doctrine's ConsoleRunner and let it handle everything.
     return \yii\base\Controller::runAction($id, $params);
 }
All Usage Examples Of yii\base\Controller::runAction