mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 14:26:54 +08:00
Fixed globalOptions array issue.
This commit is contained in:
@ -61,16 +61,21 @@ class Controller extends \yii\base\Controller
|
|||||||
* @param array $params the parameters (name-value pairs) to be passed to the action.
|
* @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.
|
* @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 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
|
* @see createAction
|
||||||
*/
|
*/
|
||||||
public function runAction($id, $params = [])
|
public function runAction($id, $params = [])
|
||||||
{
|
{
|
||||||
if (!empty($params)) {
|
if (!empty($params)) {
|
||||||
|
// populate global options here so that they are available in beforeAction().
|
||||||
$options = $this->globalOptions();
|
$options = $this->globalOptions();
|
||||||
foreach ($params as $name => $value) {
|
foreach ($params as $name => $value) {
|
||||||
if (in_array($name, $options, true)) {
|
if (in_array($name, $options, true)) {
|
||||||
$this->$name = $value;
|
$default = $this->$name;
|
||||||
|
$this->$name = is_array($default) ? preg_split('/\s*,\s*/', $value) : $value;
|
||||||
unset($params[$name]);
|
unset($params[$name]);
|
||||||
|
} elseif (!is_int($name)) {
|
||||||
|
throw new Exception(Yii::t('yii', 'Unknown option: --{name}', ['name' => $name]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,27 +94,14 @@ class Controller extends \yii\base\Controller
|
|||||||
*/
|
*/
|
||||||
public function bindActionParams($action, $params)
|
public function bindActionParams($action, $params)
|
||||||
{
|
{
|
||||||
$args = [];
|
|
||||||
if (!empty($params)) {
|
|
||||||
$options = $this->globalOptions();
|
|
||||||
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;
|
|
||||||
} elseif (is_int($name)) {
|
|
||||||
$args[] = $value;
|
|
||||||
} else {
|
|
||||||
throw new Exception(Yii::t('yii', 'Unknown option: --{name}', ['name' => $name]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($action instanceof InlineAction) {
|
if ($action instanceof InlineAction) {
|
||||||
$method = new \ReflectionMethod($this, $action->actionMethod);
|
$method = new \ReflectionMethod($this, $action->actionMethod);
|
||||||
} else {
|
} else {
|
||||||
$method = new \ReflectionMethod($action, 'run');
|
$method = new \ReflectionMethod($action, 'run');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$args = array_values($params);
|
||||||
|
|
||||||
$missing = [];
|
$missing = [];
|
||||||
foreach ($method->getParameters() as $i => $param) {
|
foreach ($method->getParameters() as $i => $param) {
|
||||||
if ($param->isArray() && isset($args[$i])) {
|
if ($param->isArray() && isset($args[$i])) {
|
||||||
|
Reference in New Issue
Block a user