yii\base\Action::runWithParams PHP Метод

runWithParams() публичный Метод

This method is mainly invoked by the controller.
public runWithParams ( array $params ) : mixed
$params array the parameters to be bound to the action's run() method.
Результат mixed the result of the action
    public function runWithParams($params)
    {
        if (!method_exists($this, 'run')) {
            throw new InvalidConfigException(get_class($this) . ' must define a "run()" method.');
        }
        $args = $this->controller->bindActionParams($this, $params);
        Yii::trace('Running action: ' . get_class($this) . '::run()', __METHOD__);
        if (Yii::$app->requestedParams === null) {
            Yii::$app->requestedParams = $args;
        }
        if ($this->beforeRun()) {
            $result = call_user_func_array([$this, 'run'], $args);
            $this->afterRun();
            return $result;
        } else {
            return null;
        }
    }

Usage Example

Пример #1
0
 /**
  * @inheritdoc
  *
  * @param array $params
  * @return mixed|\yii\web\Response
  * @throws Exception
  * @throws \yii\base\InvalidConfigException
  */
 public function runWithParams($params)
 {
     if (!$this->createModel()) {
         return parent::runWithParams($params);
     }
     if ($this->loadAndValidateRequest()) {
         return parent::runWithParams($params);
     }
     return Response::fail(400, $this->model->getErrors());
 }