Class yii\bootstrap\Dropdown
Inheritance | yii\bootstrap\Dropdown » yii\bootstrap\Widget » yii\base\Widget |
---|---|
Uses Traits | yii\bootstrap\BootstrapWidgetTrait |
Available since version | 2.0 |
Dropdown renders a Bootstrap dropdown menu component.
For example,
<div class="dropdown">
<a href="#" data-toggle="dropdown" class="dropdown-toggle">Label <b class="caret"></b></a>
<?php
echo Dropdown::widget([
'items' => [
['label' => 'DropdownA', 'url' => '/'],
['label' => 'DropdownB', 'url' => '#'],
],
]);
?>
</div>
Public 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 |
$encodeLabels | boolean | Whether the labels for header items should be HTML-encoded. | yii\bootstrap\Dropdown |
$items | array | List of menu items in the dropdown. | yii\bootstrap\Dropdown |
$options | array | The HTML attributes for the widget container tag. | yii\bootstrap\Widget |
$submenuOptions | array|null | The HTML attributes for sub-menu container tags. | yii\bootstrap\Dropdown |
Public Methods
Method | Description | Defined By |
---|---|---|
getView() | yii\bootstrap\BootstrapWidgetTrait | |
init() | Initializes the widget. | yii\bootstrap\Dropdown |
run() | Renders the widget. | yii\bootstrap\Dropdown |
Protected 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 |
renderItems() | Renders menu items. | yii\bootstrap\Dropdown |
Property Details
Whether the labels for header items should be HTML-encoded.
List of menu items in the dropdown. Each array element can be either an HTML string, or an array representing a single menu with the following structure:
- label: string, required, the label of the item link.
- encode: bool, optional, whether to HTML-encode item label.
- url: string|array, optional, the URL of the item link. This will be processed by \yii\helpers\Url::to(). If not set, the item will be treated as a menu header when the item has no sub-menu.
- visible: bool, optional, whether this menu item is visible. Defaults to true.
- linkOptions: array, optional, the HTML attributes of the item link.
- options: array, optional, the HTML attributes of the item.
- items: array, optional, the submenu items. The structure is the same as this property. Note that Bootstrap doesn't support dropdown submenu. You have to add your own CSS styles to support it.
- submenuOptions: array, optional, the HTML attributes for sub-menu container tag. If specified it will be merged with $submenuOptions.
To insert divider use <li role="presentation" class="divider"></li>
.
The HTML attributes for sub-menu container tags. If not set - $options value will be used for it.
Method Details
Initializes the widget.
If you override this method, make sure you call the parent implementation first.
public void init ( ) |
Renders menu items.
protected string renderItems ( $items, $options = [] ) | ||
$items | array | The menu items to be rendered |
$options | array | The container HTML attributes |
return | string | The rendering result. |
---|---|---|
throws | \yii\base\InvalidConfigException | if the label option is not specified in one of the items. |
Renders the widget.
public void run ( ) |