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); }
/** * 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 integer 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. * @see createAction */ public function runAction($id, $params = []) { if (!empty($params)) { $options = $this->globalOptions(); foreach ($params as $name => $value) { if (in_array($name, $options, true)) { $this->{$name} = $value; unset($params[$name]); } } } return parent::runAction($id, $params); }
/** @inheritdoc */ public function runAction($id, $consoleParams = [], $params = []) { if (!empty($consoleParams)) { $options = $this->options($id); foreach ($consoleParams as $name => $value) { if (in_array($name, $options, true)) { $default = $this->{$name}; $this->{$name} = is_array($default) ? preg_split('/\\s*,\\s*/', $value) : $value; unset($consoleParams[$name]); } elseif (!is_int($name)) { throw new Exception(Yii::t('yii', 'Unknown option: --{name}', ['name' => $name])); } } } return BaseController::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 integer 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 */ public function runAction($id, $params = []) { if (!empty($params)) { // populate options here so that they are available in beforeAction(). $options = $this->options($id); foreach ($params as $name => $value) { if (in_array($name, $options, true)) { $default = $this->{$name}; $this->{$name} = is_array($default) ? preg_split('/\\s*,\\s*/', $value) : $value; unset($params[$name]); } elseif (!is_int($name)) { throw new Exception(Yii::t('yii', 'Unknown option: --{name}', ['name' => $name])); } } } 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 integer 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 */ 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) { if (in_array($name, $options, true)) { $default = $this->{$name}; if (is_array($default)) { $this->{$name} = preg_split('/(?!\\(\\d+)\\s*,\\s*(?!\\d+\\))/', $value); } elseif ($default !== null) { settype($value, gettype($default)); $this->{$name} = $value; } else { $this->{$name} = $value; } $this->_passedOptions[] = $name; unset($params[$name]); } elseif (!is_int($name)) { throw new Exception(Yii::t('yii', 'Unknown option: --{name}', ['name' => $name])); } } } return parent::runAction($id, $params); }
public function runAction($id, $params = array()) { $params = array_merge($_POST, $params); 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 integer 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 */ public function runAction($id, $params = []) { if (!empty($params)) { // populate options here so that they are available in beforeAction(). // 获取允许的参数,可以在beforeAction中拿到 $options = $this->options($id); foreach ($params as $name => $value) { if (in_array($name, $options, true)) { // 如果参数在允许的options,才会将值赋给controller的属性 $default = $this->{$name}; // 如果该属性的默认值是数组,就根据逗号和空格(包含" ", \r, \t, \n, \f)的组合分隔value值 $this->{$name} = is_array($default) ? preg_split('/\\s*,\\s*/', $value) : $value; unset($params[$name]); } elseif (!is_int($name)) { throw new Exception(Yii::t('yii', 'Unknown option: --{name}', ['name' => $name])); } } } return parent::runAction($id, $params); }