PHP code example of kartik-v / yii2-bootstrap4-dropdown
1. Go to this page and download the library: Download kartik-v/yii2-bootstrap4-dropdown library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
kartik-v / yii2-bootstrap4-dropdown example snippets
use yii\bootstrap4\NavBar;
use yii\bootstrap4\Nav;
use kartik\bs4dropdown\Dropdown;
use yii\helpers\Html;
NavBar::begin(['brandLabel' => 'NavBar Test']);
echo Nav::widget([
'items' => [
['label' => 'Home', 'url' => ['/site/index']],
[
'label' => 'Dropdown',
'items' => [
['label' => 'Section 1', 'url' => '/'],
['label' => 'Section 2', 'url' => '#'],
[
'label' => 'Section 3',
'items' => [
['label' => 'Section 3.1', 'url' => '/'],
['label' => 'Section 3.2', 'url' => '#'],
[
'label' => 'Section 3.3',
'items' => [
['label' => 'Section 3.3.1', 'url' => '/'],
['label' => 'Section 3.3.2', 'url' => '#'],
],
],
],
],
],
],
['label' => 'About', 'url' => ['/site/about']],
],
'dropdownClass' => Dropdown::classname(), // use the custom dropdown
'options' => ['class' => 'navbar-nav mr-auto'],
]);
NavBar::end();
<div class="dropdown">
echo Html::button('Dropdown Button', [
'id' => 'dropdownMenuButton',
'class' => 'btn btn-secondary dropdown-toggle'
'data-toggle' => 'dropdown',
'aria-haspopup' => 'true',
'aria-expanded' => 'false'
]);
echo Dropdown::widget([
'items' => [
['label' => 'Section 1', 'url' => '/'],
['label' => 'Section 2', 'url' => '#'],
[
'label' => 'Section 3',
'items' => [
['label' => 'Section 3.1', 'url' => '/'],
['label' => 'Section 3.2', 'url' => '#'],
[
'label' => 'Section 3.3',
'items' => [
['label' => 'Section 3.3.1', 'url' => '/'],
['label' => 'Section 3.3.2', 'url' => '#'],
],
],
],
],
],
'options' => ['aria-labelledby' => 'dropdownMenuButton']
]);
use \yii\helpers\Html;
use kartik\bs4dropdown\Dropdown;
use \yii\helpers\Html;
use kartik\bs4dropdown\ButtonDropdown;
echo ButtonDropdown::widget([
'label' => 'Dropdown Button',
'dropdown' => [
'items' => [
['label' => 'Section 1', 'url' => '/'],
['label' => 'Section 2', 'url' => '#'],
[
'label' => 'Section 3',
'items' => [
['label' => 'Section 3.1', 'url' => '/'],
['label' => 'Section 3.2', 'url' => '#'],
[
'label' => 'Section 3.3',
'items' => [
['label' => 'Section 3.3.1', 'url' => '/'],
['label' => 'Section 3.3.2', 'url' => '#'],
],
],
],
],
],
],
'buttonOptions' => ['class'=>'btn-secondary']
]);