Class yii\bootstrap\Widget

Inheritanceyii\bootstrap\Widget » yii\base\Widget
Uses Traitsyii\bootstrap\BootstrapWidgetTrait
Subclassesyii\bootstrap\Alert, yii\bootstrap\Button, yii\bootstrap\ButtonDropdown, yii\bootstrap\ButtonGroup, yii\bootstrap\Carousel, yii\bootstrap\Collapse, yii\bootstrap\Dropdown, yii\bootstrap\Modal, yii\bootstrap\Nav, yii\bootstrap\NavBar, yii\bootstrap\Progress, yii\bootstrap\Tabs
Available since extension's version2.0
Source Code https://github.com/yiisoft/yii2-bootstrap/blob/master/src/Widget.php

\yii\bootstrap\Widget is the base class for all bootstrap widgets.

Public Properties

Hide inherited properties

Property Type Description Defined By
$clientEvents array The event handlers for the underlying Bootstrap JS plugin. yii\bootstrap\BootstrapWidgetTrait
$clientOptions array The options for the underlying Bootstrap JS plugin. yii\bootstrap\BootstrapWidgetTrait
$options array The HTML attributes for the widget container tag. yii\bootstrap\Widget

Public Methods

Hide inherited methods

Method Description Defined By
getView() yii\bootstrap\BootstrapWidgetTrait
init() Initializes the widget. yii\bootstrap\BootstrapWidgetTrait

Protected Methods

Hide inherited methods

Method Description Defined By
registerClientEvents() Registers JS event handlers that are listed in $clientEvents. yii\bootstrap\BootstrapWidgetTrait
registerPlugin() Registers a specific Bootstrap plugin and the related events yii\bootstrap\BootstrapWidgetTrait

Property Details

Hide inherited properties

$options public property

The HTML attributes for the widget container tag.

See also \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.

public array $options = []

Method Details

Hide inherited methods

getView() public abstract method

Defined in: yii\bootstrap\BootstrapWidgetTrait::getView()

See also \yii\base\Widget::getView().

public abstract \yii\web\View getView ( )
return \yii\web\View

The view object that can be used to render views or view files.

                abstract function getView();

            
init() public method

Defined in: yii\bootstrap\BootstrapWidgetTrait::init()

Initializes the widget.

This method will register the bootstrap asset bundle. If you override this method, make sure you call the parent implementation first.

public void init ( )

                public function init()
{
    parent::init();
    if (!isset($this->options['id'])) {
        $this->options['id'] = $this->getId();
    }
}

            
registerClientEvents() protected method (available since version 2.0.2)

Defined in: yii\bootstrap\BootstrapWidgetTrait::registerClientEvents()

Registers JS event handlers that are listed in $clientEvents.

protected void registerClientEvents ( )

                protected function registerClientEvents()
{
    if (!empty($this->clientEvents)) {
        $id = $this->options['id'];
        $js = [];
        foreach ($this->clientEvents as $event => $handler) {
            $js[] = "jQuery('#$id').on('$event', $handler);";
        }
        $this->getView()->registerJs(implode("\n", $js));
    }
}

            
registerPlugin() protected method

Defined in: yii\bootstrap\BootstrapWidgetTrait::registerPlugin()

Registers a specific Bootstrap plugin and the related events

protected void registerPlugin ( $name )
$name string

The name of the Bootstrap plugin

                protected function registerPlugin($name)
{
    $view = $this->getView();
    BootstrapPluginAsset::register($view);
    $id = $this->options['id'];
    if ($this->clientOptions !== false) {
        $options = empty($this->clientOptions) ? '' : Json::htmlEncode($this->clientOptions);
        $js = "jQuery('#$id').$name($options);";
        $view->registerJs($js);
    }
    $this->registerClientEvents();
}