PHPackages                             itstructure/yii2-multi-level-menu - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. itstructure/yii2-multi-level-menu

ActivePackage

itstructure/yii2-multi-level-menu
=================================

Widget for rendering multilevel menu for Yii2 Framework

3.2.10(6mo ago)53281MITPHPPHP &gt;=7.1.0

Since May 19Pushed 6mo agoCompare

[ Source](https://github.com/itstructure/yii2-multi-level-menu)[ Packagist](https://packagist.org/packages/itstructure/yii2-multi-level-menu)[ RSS](/packages/itstructure-yii2-multi-level-menu/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (1)Versions (17)Used By (0)

Yii2 Multilevel menu widget
===========================

[](#yii2-multilevel-menu-widget)

Introduction
------------

[](#introduction)

[![Latest Stable Version](https://camo.githubusercontent.com/2b9ac2df5112452fcfc2ff74a110cdd8486de8a32b58c345b8d70c72b6e9946b/68747470733a2f2f706f7365722e707567782e6f72672f69747374727563747572652f796969322d6d756c74692d6c6576656c2d6d656e752f762f737461626c65)](https://packagist.org/packages/itstructure/yii2-multi-level-menu)[![Latest Unstable Version](https://camo.githubusercontent.com/f36bad23189dc091bec9f111c39748b4d9854832f7b18c725dade7f0338ec9e9/68747470733a2f2f706f7365722e707567782e6f72672f69747374727563747572652f796969322d6d756c74692d6c6576656c2d6d656e752f762f756e737461626c65)](https://packagist.org/packages/itstructure/yii2-multi-level-menu)[![License](https://camo.githubusercontent.com/24242c44bbf58ea6a73c8c88b19c0243173d89e9f2000718be0b05db61b93f96/68747470733a2f2f706f7365722e707567782e6f72672f69747374727563747572652f796969322d6d756c74692d6c6576656c2d6d656e752f6c6963656e7365)](https://packagist.org/packages/itstructure/yii2-multi-level-menu)[![Total Downloads](https://camo.githubusercontent.com/9f49afb3e625376e98fb25447e9831446aa2d2aac0861d2d98760a19099130f4/68747470733a2f2f706f7365722e707567782e6f72672f69747374727563747572652f796969322d6d756c74692d6c6576656c2d6d656e752f646f776e6c6f616473)](https://packagist.org/packages/itstructure/yii2-multi-level-menu)[![Build Status](https://camo.githubusercontent.com/670173fe52dbaa7850b533404567dad594a2bb8be7cc7c626e28110c2b136824/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f69747374727563747572652f796969322d6d756c74692d6c6576656c2d6d656e752f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/itstructure/yii2-multi-level-menu/build-status/master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/0e6b6a0710a4c4c550bb9324dcaad15be86f84570ad97ac48aa17dbcef3607c7/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f69747374727563747572652f796969322d6d756c74692d6c6576656c2d6d656e752f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/itstructure/yii2-multi-level-menu/?branch=master)

This widget is designed to display a multilevel menu, in which there can be nested submenus. Used for Yii2 v2.0.x framework.

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

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

[![Multi level menu example scheme](https://github.com/itstructure/yii2-multi-level-menu/raw/master/ML_menu_en.jpg)](https://github.com/itstructure/yii2-multi-level-menu/blob/master/ML_menu_en.jpg)

Requirements
------------

[](#requirements)

- php &gt;= 7.1
- composer 2

Installation
------------

[](#installation)

Via composer:

`composer require itstructure/yii2-multi-level-menu ~3.2.10`

Usage
-----

[](#usage)

### Usage in view template

[](#usage-in-view-template)

Base application config must be like in example below:

```
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:

```
use yii\helpers\{Url, Html};
/* @var app\models\Page $data */
```

```

```

Example when there are some properties for nesting levels:

```
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:

```
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

[](#database-table-structure-example)

`Table "pages"`

```
| 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
-------

[](#license)

Copyright © 2018-2025 Andrey Girnik .

Licensed under the [MIT license](http://opensource.org/licenses/MIT). See LICENSE.txt for details.

###  Health Score

43

—

FairBetter than 90% of packages

Maintenance70

Regular maintenance activity

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~180 days

Recently: every ~480 days

Total

16

Last Release

201d ago

Major Versions

1.1.0 → 2.0.02018-05-22

2.0.0 → 3.0.02018-05-23

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/31563329?v=4)[Andrey Girnik](/maintainers/itstructure)[@itstructure](https://github.com/itstructure)

---

Top Contributors

[![itstructure](https://avatars.githubusercontent.com/u/31563329?v=4)](https://github.com/itstructure "itstructure (19 commits)")

---

Tags

menumultilevel-menuyii2menuyii2yii 2multilevel

### Embed Badge

![Health badge](/badges/itstructure-yii2-multi-level-menu/health.svg)

```
[![Health](https://phpackages.com/badges/itstructure-yii2-multi-level-menu/health.svg)](https://phpackages.com/packages/itstructure-yii2-multi-level-menu)
```

###  Alternatives

[softark/yii2-dual-listbox

Bootstrap Dual Listbox Widget for Yii 2

20144.4k11](/packages/softark-yii2-dual-listbox)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
