yii\base\Widget::widget PHP Method

widget() public static method

The widget rendering result is returned by this method.
public static widget ( array $config = [] ) : string
$config array name-value pairs that will be used to initialize the object properties
return string the rendering result of the widget.
    public static function widget($config = [])
    {
        ob_start();
        ob_implicit_flush(false);
        try {
            /* @var $widget Widget */
            $config['class'] = get_called_class();
            $widget = Yii::createObject($config);
            $out = $widget->run();
        } catch (\Exception $e) {
            // close the output buffer opened above if it has not been closed already
            if (ob_get_level() > 0) {
                ob_end_clean();
            }
            throw $e;
        }
        return ob_get_clean() . $out;
    }

Usage Example

Beispiel #1
0
 public static function widget($config = [])
 {
     if (isset($config['options'])) {
         $options =& $config['options'];
     }
     $vars = get_class_vars(get_class());
     foreach ($config as $k => $v) {
         if (array_key_exists($k, $vars)) {
             continue;
         }
         $options[$k] = $v;
         unset($config[$k]);
     }
     return parent::widget($config);
 }
All Usage Examples Of yii\base\Widget::widget