2017 © Pedro Peláez
 

package yii2-multi-level-menu

Widget for rendering multilevel menu for Yii2 Framework

image

itstructure/yii2-multi-level-menu

Widget for rendering multilevel menu for Yii2 Framework

  • Wednesday, June 27, 2018
  • by itstructure
  • Repository
  • 0 Watchers
  • 0 Stars
  • 18 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 10 Versions
  • 80 % Grown

The README.md

Yii2 Multilevel menu widget

Introduction

Latest Stable Version Latest Unstable Version License Total Downloads Build Status Scrutinizer Code Quality, (*1)

This widget is designed to display a multilevel menu, in which there can be nested submenus. Used for Yii2 framework., (*2)

The widget uses data from the database, in which there are, in addition to the primary keys, also the parent keys., (*3)

Data from the database is taken from an active model, which instance of yii\db\ActiveRecord., (*4)

Multi level menu example scheme, (*5)

Requirements

  • php >= 7.1
  • composer

Installation

Via composer:, (*6)

composer require itstructure/yii2-multi-level-menu ~3.2.9, (*7)

Usage

Usage in view template

Base application config must be like in example below:, (*8)

use Itstructure\MultiLevelMenu\MenuWidget;
echo MenuWidget::widget([
    'menuId' => 'multi-level-menu',
    'data' => array_values($dataProvider->getModels()),
    'itemTemplate' => '@app/views/MultiLevelMenu/main.php'
]);

Example of itemTemplate file:, (*9)

use yii\helpers\{Url, Html};
/* @var app\models\Page $data */
<span>
    <?php echo Html::a(
        Html::encode($data->title),
        Url::to(['view', 'id' => $data->id])
    ) ?>
</span>

Example when there are some properties for nesting levels:, (*10)

use Itstructure\MultiLevelMenu\MenuWidget;
echo MenuWidget::widget([
    'menuId' => 'multi-level-menu',
    'data' => array_values($dataProvider->getModels()),
    'itemTemplate' => '@app/views/MultiLevelMenu/main.php'
    'mainContainerOptions' => [
        'class' => 'list-group'
    ],
    'itemContainerOptions' => [
        'levels' => [
            ['class' => 'list-group-item'],
            ['class' => 'list-group-item list-group-item-success'],
            ['class' => 'list-group-item list-group-item-warning'],
        ]
    ],
]);

Example when there are some properties as callable function:, (*11)

use Itstructure\MultiLevelMenu\MenuWidget;
echo MenuWidget::widget([
    'menuId' => 'multi-level-menu',
    'data' => array_values($dataProvider->getModels()),
    'itemTemplate' => '@app/views/MultiLevelMenu/main.php'
    'mainContainerOptions' => function () {
        return [
            'class' => $level == 0 ? 'nav navbar-nav navbar-right' : 'dropdown-menu'
        ];
    },
    'itemTemplateParams' => function ($level, $item) {
        return [
            'linkOptions' => isset($item['items']) && count($item['items']) > 0 ? [
                'class' => 'dropdown-toggle',
                'data-toggle' => 'dropdown',
                'aria-haspopup' => 'true',
                'aria-expanded' => 'false',
            ] : [],
        ];
    },
    'itemContainerOptions' => function ($level, $item) {
        return $level == 0 ? [
            'class' => isset($item['items']) && count($item['items']) > 0 ? 'nav-item dropdown' : 'nav-item'
        ] : [
            'class' => isset($item['items']) && count($item['items']) > 0 ? 'dropdown-item dropdown' : 'dropdown-item'
        ];
    }
]);

Database table structure example

Table "pages", (*12)

| id  | parentId |   title    | ... |
|-----|----------|------------|-----|
|  1  |   NULL   |   item 1   | ... |
|  2  |   NULL   |   item 2   | ... |
|  3  |   NULL   |   item 3   | ... |
|  4  |   NULL   |   item 4   | ... |
|  5  |   NULL   |   item 5   | ... |
|  6  |     2    |  item 2.1  | ... |
|  7  |     2    |  item 2.2  | ... |
|  8  |     7    | item 2.2.1 | ... |
|  9  |     7    | item 2.2.2 | ... |
|  10 |     7    | item 2.2.3 | ... |
| ... |    ...   |     ...    | ... |

License

Copyright © 2018-2023 Andrey Girnik girnikandrey@gmail.com., (*13)

Licensed under the MIT license. See LICENSE.txt for details., (*14)

The Versions

27/06 2018

dev-master

9999999-dev

Widget for rendering multilevel menu for Yii2 Framework

  Sources   Download

MIT

The Requires

 

yii2 yii 2 menu multilevel

27/06 2018

dev-dev

dev-dev

Widget for rendering multilevel menu for Yii2 Framework

  Sources   Download

MIT

The Requires

 

yii2 yii 2 menu multilevel

27/06 2018

3.2.2

3.2.2.0

Widget for rendering multilevel menu for Yii2 Framework

  Sources   Download

MIT

The Requires

 

yii2 yii 2 menu multilevel

27/06 2018

3.2.1

3.2.1.0

Widget for rendering multilevel menu for Yii2 Framework

  Sources   Download

MIT

The Requires

 

yii2 yii 2 menu multilevel

08/06 2018

3.2.0

3.2.0.0

Widget for rendering multilevel menu for Yii2 Framework

  Sources   Download

MIT

The Requires

 

yii2 yii 2 menu multilevel

24/05 2018

3.1.0

3.1.0.0

Widget for rendering multilevel menu for Yii2 Framework

  Sources   Download

MIT

The Requires

 

yii2 yii 2 menu multilevel

23/05 2018

3.0.0

3.0.0.0

Widget for rendering multilevel menu for Yii2 Framework

  Sources   Download

MIT

The Requires

 

yii2 yii 2 menu multilevel

22/05 2018

2.0.0

2.0.0.0

Widget for rendering multilevel menu for Yii2 Framework

  Sources   Download

MIT

The Requires

 

yii2 yii 2 menu multilevel

20/05 2018

1.1.0

1.1.0.0

Widget for rendering multilevel menu for Yii2 Framework

  Sources   Download

MIT

The Requires

 

yii2 yii 2 menu multilevel

19/05 2018

1.0.0

1.0.0.0

Widget for rendering multilevel menu for Yii2 Framework

  Sources   Download

MIT

The Requires

 

yii2 yii 2 menu multilevel