From 87a6cf58af654868471b9f0e02b39a47a55bebf4 Mon Sep 17 00:00:00 2001 From: hiltonjanfield Date: Sun, 6 Apr 2014 13:22:03 -0700 Subject: [PATCH] Clarify new usage of yii\web\View::render() One paragraph description and one code snippet to clarify usage of yii\web\View::render() in a view context, as using echo is a significant change from partial view usage in Yii 1.1. --- docs/guide/upgrade-from-v1.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/guide/upgrade-from-v1.md b/docs/guide/upgrade-from-v1.md index ceba3b050c..71ceeebe39 100644 --- a/docs/guide/upgrade-from-v1.md +++ b/docs/guide/upgrade-from-v1.md @@ -151,6 +151,13 @@ accessible in any view file via `$this`. This is one of the biggest changes comp It refers to the view object that is used to render the view file. To access the controller or the widget object, you have to use `$this->context` now. +For partial views, the [[yii\web\View|View]] class now includes a `render()` function. This creates another significant change in the usage of views compared to 1.1: +**`$this->render(...)` does not output the processed content; you must echo it yourself.** + +```php +echo $this->render('_item', ['item' => $item]); +``` + Because you can access the view object through the "view" application component, you can now render a view file like the following anywhere in your code, not necessarily in controllers or widgets: