Added yii\base\Controller::renderContent()

This commit is contained in:
Qiang Xue
2014-11-16 23:16:37 -05:00
parent 439c2e4d11
commit 3c63213de3
3 changed files with 19 additions and 4 deletions

View File

@ -364,17 +364,29 @@ class Controller extends Component implements ViewContextInterface
*/
public function render($view, $params = [])
{
$output = $this->getView()->render($view, $params, $this);
$content = $this->getView()->render($view, $params, $this);
return $this->renderContent($content);
}
/**
* Renders a static string by applying a layout.
* @param string $content the static string being rendered
* @return string the rendering result of the layout with the given static string as the `$content` variable.
* If the layout is disabled, the string will be returned back.
* @since 2.0.1
*/
public function renderContent($content)
{
$layoutFile = $this->findLayoutFile($this->getView());
if ($layoutFile !== false) {
return $this->getView()->renderFile($layoutFile, ['content' => $output], $this);
return $this->getView()->renderFile($layoutFile, ['content' => $content], $this);
} else {
return $output;
return $content;
}
}
/**
* Renders a view.
* Renders a view without applying layout.
* This method differs from [[render()]] in that it does not apply any layout.
* @param string $view the view name. Please refer to [[render()]] on how to specify a view name.
* @param array $params the parameters (name-value pairs) that should be made available in the view.