Browse Source

document the fact that widgets use output buffering

so they may break ob stack when end() and begin() are called in
different views.

close #11687
ar-bug
Carsten Brandt 8 years ago
parent
commit
93f6ddfbe9
  1. 5
      docs/guide/structure-widgets.md
  2. 4
      framework/base/Widget.php

5
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

4
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()
{

Loading…
Cancel
Save