diff --git a/docs/guide/structure-widgets.md b/docs/guide/structure-widgets.md index 27cde16..55ddb1f 100644 --- a/docs/guide/structure-widgets.md +++ b/docs/guide/structure-widgets.md @@ -68,6 +68,11 @@ use yii\helpers\Html; Note that unlike [[yii\base\Widget::widget()]] which returns the rendering result of a widget, the method [[yii\base\Widget::begin()]] returns an instance of the widget which you can use to build the widget content. +> Note: Some widgets will use [output buffering](http://php.net/manual/en/book.outcontrol.php) to adjust the enclosed +> content when [[yii\base\Widget::end()]] is called. For this reason calling [[yii\base\Widget::begin()]] and +> [[yii\base\Widget::end()]] is expected to happen in the same view file. +> Not following this rule may result in unexpected output. + ### Configuring global defaults diff --git a/framework/base/Widget.php b/framework/base/Widget.php index 7282d34..9f5d477 100644 --- a/framework/base/Widget.php +++ b/framework/base/Widget.php @@ -46,8 +46,11 @@ class Widget extends Component implements ViewContextInterface * Begins a widget. * This method creates an instance of the calling class. It will apply the configuration * to the created instance. A matching [[end()]] call should be called later. + * As some widgets may use output buffering, the [[end()]] call should be made in the same view + * to avoid breaking the nesting of output buffers. * @param array $config name-value pairs that will be used to initialize the object properties * @return static the newly created widget instance + * @see end() */ public static function begin($config = []) { @@ -64,6 +67,7 @@ class Widget extends Component implements ViewContextInterface * Note that the rendering result of the widget is directly echoed out. * @return static the widget instance that is ended. * @throws InvalidCallException if [[begin()]] and [[end()]] calls are not properly nested + * @see begin() */ public static function end() {