Commit 3c63213d by Qiang Xue

Added `yii\base\Controller::renderContent()`

parent 439c2e4d
......@@ -127,6 +127,8 @@ Within [controllers](structure-controllers.md), you may call the following contr
and injects all registered JS/CSS scripts and files. It is usually used in response to AJAX Web requests.
* [[yii\base\Controller::renderFile()|renderFile()]]: renders a view specified in terms of a view file path or
[alias](concept-aliases.md).
* [[yii\base\Controller::renderContent()|renderContent()]]: renders a static string by embedding it into
the currently applicable [layout](#layouts). This method is available since version 2.0.1.
For example,
......
......@@ -52,6 +52,7 @@ Yii Framework 2 Change Log
- Enh #5983: Added `Inflector::sentence()` (pana1990, qiangxue)
- Enh: `Console::confirm()` now uses `Console::stdout()` instead of `echo` to be consistent with all other functions (cebe)
- Enh: `yii\rbac\DbManager` migration now uses database component specified in component settings instead of always using default `db` (samdark)
- Enh: Added `yii\base\Controller::renderContent()` (qiangxue)
- Chg #3630: `yii\db\Command::queryInternal()` is now protected (samdark)
- Chg #5508: Dropped the support for the `--append` option for the `fixture` command (qiangxue)
- Chg #5874: Upgraded Twitter Bootstrap to 3.3.x (samdark)
......
......@@ -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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment