yii\web\ViewAction::run PHP Method

run() public method

This method displays the view requested by the user.
public run ( )
    public function run()
    {
        $viewName = $this->resolveViewName();
        $this->controller->actionParams[$this->viewParam] = Yii::$app->request->get($this->viewParam);
        $controllerLayout = null;
        if ($this->layout !== null) {
            $controllerLayout = $this->controller->layout;
            $this->controller->layout = $this->layout;
        }
        try {
            $output = $this->render($viewName);
            if ($controllerLayout) {
                $this->controller->layout = $controllerLayout;
            }
        } catch (ViewNotFoundException $e) {
            if ($controllerLayout) {
                $this->controller->layout = $controllerLayout;
            }
            if (YII_DEBUG) {
                throw new NotFoundHttpException($e->getMessage());
            } else {
                throw new NotFoundHttpException(Yii::t('yii', 'The requested view "{name}" was not found.', ['name' => $viewName]));
            }
        }
        return $output;
    }

Usage Example

Beispiel #1
0
 /**
  * @return mixed|string
  * @throws InvalidConfigException
  * @throws \yii\web\NotFoundHttpException
  */
 public function run()
 {
     if ($this->callback) {
         if (!is_callable($this->callback)) {
             throw new InvalidConfigException('"' . get_class($this) . '::callback" ' . \Yii::t('app', 'should be a valid callback.'));
         }
         return call_user_func($this->callback, $this);
     }
     return parent::run();
 }