framework/console/Controller.php
public function runAction($id, $params = [])
    {
        if (!empty($params)) {
            // populate options here so that they are available in beforeAction().
            $options = $this->options($id === '' ? $this->defaultAction : $id);
            if (isset($params['_aliases'])) {
                $optionAliases = $this->optionAliases();
                foreach ($params['_aliases'] as $name => $value) {
                    if (array_key_exists($name, $optionAliases)) {
                        $params[$optionAliases[$name]] = $value;
                    } else {
                        throw new Exception(Yii::t('yii', 'Unknown alias: -{name}', ['name' => $name]));
                    }
                }
                unset($params['_aliases']);
            }
            foreach ($params as $name => $value) {
                // Allow camelCase options to be entered in kebab-case
                if (!in_array($name, $options, true) && strpos($name, '-') !== false) {
                    $kebabName = $name;
                    $altName = lcfirst(Inflector::id2camel($kebabName));
                    if (in_array($altName, $options, true)) {
                        $name = $altName;
                    }
                }

                if (in_array($name, $options, true)) {
                    $default = $this->$name;
                    if (is_array($default)) {
                        $this->$name = preg_split('/\s*,\s*(?![^()]*\))/', $value);
                    } elseif ($default !== null) {
                        settype($value, gettype($default));
                        $this->$name = $value;
                    } else {
                        $this->$name = $value;
                    }
                    $this->_passedOptions[] = $name;
                    unset($params[$name]);
                    if (isset($kebabName)) {
                        unset($params[$kebabName]);
                    }
                } elseif (!is_int($name)) {
                    throw new Exception(Yii::t('yii', 'Unknown option: --{name}', ['name' => $name]));
                }
            }
        }
        if ($this->help) {
            $route = $this->getUniqueId() . '/' . $id;
            return Yii::$app->runAction('help', [$route]);
        }

        return parent::runAction($id, $params);
    }
public function runAction($id, $params = [])
    {
        if (!empty($params)) {
            // populate options here so that they are available in beforeAction().
            $options = $this->options($id === '' ? $this->defaultAction : $id);
            if (isset($params['_aliases'])) {
                $optionAliases = $this->optionAliases();
                foreach ($params['_aliases'] as $name => $value) {
                    if (array_key_exists($name, $optionAliases)) {
                        $params[$optionAliases[$name]] = $value;
                    } else {
                        throw new Exception(Yii::t('yii', 'Unknown alias: -{name}', ['name' => $name]));
                    }
                }
                unset($params['_aliases']);
            }
            foreach ($params as $name => $value) {
                // Allow camelCase options to be entered in kebab-case
                if (!in_array($name, $options, true) && strpos($name, '-') !== false) {
                    $kebabName = $name;
                    $altName = lcfirst(Inflector::id2camel($kebabName));
                    if (in_array($altName, $options, true)) {
                        $name = $altName;
                    }
                }

                if (in_array($name, $options, true)) {
                    $default = $this->$name;
                    if (is_array($default)) {
                        $this->$name = preg_split('/\s*,\s*(?![^()]*\))/', $value);
                    } elseif ($default !== null) {
                        settype($value, gettype($default));
                        $this->$name = $value;
                    } else {
                        $this->$name = $value;
                    }
                    $this->_passedOptions[] = $name;
                    unset($params[$name]);
                    if (isset($kebabName)) {
                        unset($params[$kebabName]);
                    }
                } elseif (!is_int($name)) {
                    throw new Exception(Yii::t('yii', 'Unknown option: --{name}', ['name' => $name]));
                }
            }
        }
        if ($this->help) {
            $route = $this->getUniqueId() . '/' . $id;
            return Yii::$app->runAction('help', [$route]);
        }

        return parent::runAction($id, $params);
    }
public function runAction ( $ id , $ params = [ ] ) { if ( ! empty ( $ params ) ) { // populate options here so that they are available in beforeAction(). $ options = $ this -> options ( $ id === '' ? $ this -> defaultAction : $ id ) ; if ( isset ( $ params [ '_aliases' ] ) ) { $ optionAliases = $ this -> optionAliases ( ) ; foreach ( $ params [ '_aliases' ] as $ name => $ value ) { if ( array_key_exists ( $ name , $ optionAliases ) ) { $ params [ $ optionAliases [ $ name ] ] = $ value ; } else { throw new Exception ( Yii :: t ( 'yii' , 'Unknown alias: -{name}' , [ 'name' => $ name ] ) ) ; } } unset ( $ params [ '_aliases' ] ) ; } foreach ( $ params as $ name => $ value ) { // Allow camelCase options to be entered in kebab-case if ( ! in_array ( $ name , $ options , true ) && strpos ( $ name , '-' ) !== false ) { $ kebabName = $ name ; $ altName = lcfirst ( Inflector :: id2camel ( $ kebabName ) ) ; if ( in_array ( $ altName , $ options , true ) ) { $ name = $ altName ; } } if ( in_array ( $ name , $ options , true ) ) { $ default = $ this -> $ name ; if ( is_array ( $ default ) ) { $ this -> $ name = preg_split ( '/\s*,\s*(?![^()]*\))/' , $ value ) ; } elseif ( $ default !== null ) { settype ( $ value , gettype ( $ default ) ) ; $ this -> $ name = $ value ; } else { $ this -> $ name = $ value ; } $ this -> _passedOptions [ ] = $ name ; unset ( $ params [ $ name ] ) ; if ( isset ( $ kebabName ) ) { unset ( $ params [ $ kebabName ] ) ; } } elseif ( ! is_int ( $ name ) ) { throw new Exception ( Yii :: t ( 'yii' , 'Unknown option: --{name}' , [ 'name' => $ name ] ) ) ; } } } if ( $ this -> help ) { $ route = $ this -> getUniqueId ( ) . '/' . $ id ; return Yii :: $ app -> runAction ( 'help' , [ $ route ] ) ; } return parent :: runAction ( $ id , $ params ) ; }
Runs an action 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 int the status of the action execution. 0 means normal, other values mean abnormal.
@throws InvalidRouteException if the requested action ID cannot be resolved into an action successfully.
@throws Exception if there are unknown options or missing arguments
@see createAction
Runs an action with the specified action ID and parameters . If the action ID is empty the method will use [[ defaultAction ]] .