yii\web\Controller::bindActionParams PHP Method

bindActionParams() public method

This method is invoked by Action when it begins to run with the given parameters. This method will check the parameter names that the action requires and return the provided parameters according to the requirement. If there is any missing parameter, an exception will be thrown.
public bindActionParams ( Action $action, array $params ) : array
$action yii\base\Action the action to be bound with parameters
$params array the parameters to be bound to the action
return array the valid parameters that the action can run with.
    public function bindActionParams($action, $params)
    {
        if ($action instanceof InlineAction) {
            $method = new \ReflectionMethod($this, $action->actionMethod);
        } else {
            $method = new \ReflectionMethod($action, 'run');
        }
        $args = [];
        $missing = [];
        $actionParams = [];
        foreach ($method->getParameters() as $param) {
            $name = $param->getName();
            if (array_key_exists($name, $params)) {
                if ($param->isArray()) {
                    $args[] = $actionParams[$name] = (array) $params[$name];
                } elseif (!is_array($params[$name])) {
                    $args[] = $actionParams[$name] = $params[$name];
                } else {
                    throw new BadRequestHttpException(Yii::t('yii', 'Invalid data received for parameter "{param}".', ['param' => $name]));
                }
                unset($params[$name]);
            } elseif ($param->isDefaultValueAvailable()) {
                $args[] = $actionParams[$name] = $param->getDefaultValue();
            } else {
                $missing[] = $name;
            }
        }
        if (!empty($missing)) {
            throw new BadRequestHttpException(Yii::t('yii', 'Missing required parameters: {params}', ['params' => implode(', ', $missing)]));
        }
        $this->actionParams = $actionParams;
        return $args;
    }