Class yii\bootstrap4\ButtonToolbar

Inheritanceyii\bootstrap4\ButtonToolbar » yii\bootstrap4\Widget » yii\base\Widget
Uses Traitsyii\bootstrap4\BootstrapWidgetTrait

ButtonToolbar Combines sets of button groups into button toolbars for more complex components.

Use utility classes as needed to space out groups, buttons, and more.

For example,

// a button toolbar with items configuration
echo ButtonToolbar::widget([
    'buttonGroups' => [
        [
            'buttons' => [
                ['label' => '1', 'class' => ['btn-secondary']],
                ['label' => '2', 'class' => ['btn-secondary']],
                ['label' => '3', 'class' => ['btn-secondary']],
                ['label' => '4', 'class' => ['btn-secondary']]
            ],
             'class' => ['mr-2']
        ],
        [
            'buttons' => [
                ['label' => '5', 'class' => ['btn-secondary']],
                ['label' => '6', 'class' => ['btn-secondary']],
                ['label' => '7', 'class' => ['btn-secondary']]
            ],
            'class' => ['mr-2']
        ],
        [
            'buttons' => [
                ['label' => '8', 'class' => ['btn-secondary']]
            ]
        ]
    ]
]);

Pressing on the button should be handled via JavaScript. See the following for details:

See also:

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$buttonGroups array List of buttons groups. yii\bootstrap4\ButtonToolbar
$clientEvents array The event handlers for the underlying Bootstrap JS plugin. yii\bootstrap4\BootstrapWidgetTrait
$clientOptions array The options for the underlying Bootstrap JS plugin. yii\bootstrap4\BootstrapWidgetTrait
$options array The HTML attributes for the widget container tag. yii\bootstrap4\Widget

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
registerClientEvents() Registers JS event handlers that are listed in $clientEvents. yii\bootstrap4\BootstrapWidgetTrait
registerPlugin() Registers a specific Bootstrap plugin and the related events yii\bootstrap4\BootstrapWidgetTrait
renderButtonGroups() Generates the button groups that compound the toolbar as specified on $buttonGroups. yii\bootstrap4\ButtonToolbar

Property Details

$buttonGroups public property

List of buttons groups. Each array element represents a single group which can be specified as a string or an array of the following structure:

  • buttons: array list of buttons. Either as array or string representation
  • options: array optional, the HTML attributes of the button group.
  • encodeLabels: bool whether to HTML-encode the button labels.
public array $buttonGroups = []

Method Details

init() public method

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 ( )
renderButtonGroups() protected method

Generates the button groups that compound the toolbar as specified on $buttonGroups.

protected string renderButtonGroups ( )
return string

The rendering result.

throws Exception
run() public method

public void run ( )
throws Exception