mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-02 04:37:42 +08:00
Added yii\base\Controller::renderContent()
This commit is contained in:
@ -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.
|
||||
|
||||
Reference in New Issue
Block a user