yii\base\View::renderFile PHP Method

renderFile() public method

If [[theme]] is enabled (not null), it will try to render the themed version of the view file as long as it is available. The method will call [[FileHelper::localize()]] to localize the view file. If [[renderers|renderer]] is enabled (not null), the method will use it to render the view file. Otherwise, it will simply include the view file as a normal PHP file, capture its output and return it as a string.
public renderFile ( string $viewFile, array $params = [], object $context = null ) : string
$viewFile string the view file. This can be either an absolute file path or an alias of it.
$params array the parameters (name-value pairs) that will be extracted and made available in the view file.
$context object the context that the view should use for rendering the view. If null, existing [[context]] will be used.
return string the rendering result
    public function renderFile($viewFile, $params = [], $context = null)
    {
        $viewFile = Yii::getAlias($viewFile);
        if ($this->theme !== null) {
            $viewFile = $this->theme->applyTo($viewFile);
        }
        if (is_file($viewFile)) {
            $viewFile = FileHelper::localize($viewFile);
        } else {
            throw new ViewNotFoundException("The view file does not exist: {$viewFile}");
        }
        $oldContext = $this->context;
        if ($context !== null) {
            $this->context = $context;
        }
        $output = '';
        $this->_viewFiles[] = $viewFile;
        if ($this->beforeRender($viewFile, $params)) {
            Yii::trace("Rendering view file: {$viewFile}", __METHOD__);
            $ext = pathinfo($viewFile, PATHINFO_EXTENSION);
            if (isset($this->renderers[$ext])) {
                if (is_array($this->renderers[$ext]) || is_string($this->renderers[$ext])) {
                    $this->renderers[$ext] = Yii::createObject($this->renderers[$ext]);
                }
                /* @var $renderer ViewRenderer */
                $renderer = $this->renderers[$ext];
                $output = $renderer->render($this, $viewFile, $params);
            } else {
                $output = $this->renderPhpFile($viewFile, $params);
            }
            $this->afterRender($viewFile, $params, $output);
        }
        array_pop($this->_viewFiles);
        $this->context = $oldContext;
        return $output;
    }