PHPackages                             zentlix/knp-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. zentlix/knp-menu

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

zentlix/knp-menu
================

The package provides object-oriented menus for projects based on the Spiral Framework

v1.1.0(2y ago)1867[1 PRs](https://github.com/zentlix/knp-menu/pulls)MITPHPPHP ^8.1

Since Jan 8Pushed 2y ago1 watchersCompare

[ Source](https://github.com/zentlix/knp-menu)[ Packagist](https://packagist.org/packages/zentlix/knp-menu)[ Docs](https://github.com/zentlix/knp-menu)[ RSS](/packages/zentlix-knp-menu/feed)WikiDiscussions 1.x Synced 1mo ago

READMEChangelog (2)Dependencies (13)Versions (4)Used By (0)

KnpMenu
=======

[](#knpmenu)

[![PHP Version Require](https://camo.githubusercontent.com/a7b6b44c5884598b1cfc75cc6c42eb3ab3de8a4612d655081cfd15179dc71ac9/68747470733a2f2f706f7365722e707567782e6f72672f7a656e746c69782f6b6e702d6d656e752f726571756972652f706870)](https://packagist.org/packages/zentlix/knp-menu)[![Latest Stable Version](https://camo.githubusercontent.com/8828e05cb532df73970ea13996edb5ca9b57115de5960e44d4edaeb31eb918a8/68747470733a2f2f706f7365722e707567782e6f72672f7a656e746c69782f6b6e702d6d656e752f762f737461626c65)](https://packagist.org/packages/zentlix/knp-menu)[![phpunit](https://github.com/zentlix/knp-menu/actions/workflows/phpunit.yml/badge.svg)](https://github.com/zentlix/knp-menu/actions)[![psalm](https://github.com/zentlix/knp-menu/actions/workflows/psalm.yml/badge.svg)](https://github.com/zentlix/knp-menu/actions)[![Codecov](https://camo.githubusercontent.com/29921c3c3f8737c7aa70637b1f55809ec2e11659fc361e4283cf1d00640a656f/68747470733a2f2f636f6465636f762e696f2f67682f7a656e746c69782f6b6e702d6d656e752f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/zentlix/knp-menu)[![Total Downloads](https://camo.githubusercontent.com/3a087e02188f90f95f18c7e7eca3b4c68772f91f03273bf8457b59e6ef859b81/68747470733a2f2f706f7365722e707567782e6f72672f7a656e746c69782f6b6e702d6d656e752f646f776e6c6f616473)](https://packagist.org/packages/zentlix/knp-menu)[![type-coverage](https://camo.githubusercontent.com/05a50abb84d14f7635b4a0e432af4cbd18ae6433c1fd92f77fb25ece76c7abfd/68747470733a2f2f73686570686572642e6465762f6769746875622f7a656e746c69782f6b6e702d6d656e752f636f7665726167652e737667)](https://shepherd.dev/github/zentlix/knp-menu)[![psalm-level](https://camo.githubusercontent.com/41397cc05b13e3ce96b65ea46e63362279a9d2aa11bf7a7b21d05f03a2dcd306/68747470733a2f2f73686570686572642e6465762f6769746875622f7a656e746c69782f6b6e702d6d656e752f6c6576656c2e737667)](https://shepherd.dev/github/zentlix/knp-menu)

The package provides object-oriented menus for projects based on the Spiral Framework.

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

[](#requirements)

Make sure that your server is configured with following PHP version and extensions:

- PHP 8.1+
- Spiral framework 3.5+

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

[](#installation)

You can install the package via composer:

```
composer require zentlix/knp-menu
```

To enable the package, you just need to add `Spiral\KnpMenu\Bootloader\KnpMenuBootloader`to the bootloaders list, which is located in the class of your application.

```
protected const LOAD = [
    // ...
    \Spiral\KnpMenu\Bootloader\KnpMenuBootloader::class,
];
```

> **Note**If you are using [`spiral-packages/discoverer`](https://github.com/spiral-packages/discoverer), you don't need to register bootloader by yourself.

Configuration
-------------

[](#configuration)

The configuration file for this package should be located at `app/config/knp-menu.php`. Within this file, you may configure default `template` and `template_options` for all menus. Also, you can register `menus`.

For example, the configuration file might look like this.

```
use App\Menu\Sidebar;
use App\Menu\TopBar;
use App\Menu\OtherMenu;
use Spiral\Core\Container\Autowire;

return [
    /**
     * -------------------------------------------------------------------------
     *  Default template for all menus
     * -------------------------------------------------------------------------
     */
    'template' => 'menu.twig',

    /**
     * -------------------------------------------------------------------------
     *  Template options for all menus
     * -------------------------------------------------------------------------
     */
    'template_options' => [
        'foo' => 'bar'
    ],

    /**
     * -------------------------------------------------------------------------
     *  Application menus list
     * -------------------------------------------------------------------------
     *
     *  As a key, you can specify the name of the menu, using this key you can get the menu.
     *  If the key is not specified, the fully qualified name of the class will be used as the key.
     */
    'menus' => [
        'sidebar' => Sidebar::class,
        'top-bar' => new Autowire(TopBar::class),
        'other' => new OtherMenu()
    ]
];
```

Creating a menu
---------------

[](#creating-a-menu)

To create a menu, create a class and implement interface `Spiral\KnpMenu\MenuInterface`.

```
namespace App\Menu;

use Knp\Menu\FactoryInterface;
use Knp\Menu\ItemInterface;
use Spiral\KnpMenu\MenuInterface;

final class Sidebar implements MenuInterface
{
    public function __construct(
        private readonly FactoryInterface $factory
    ) {
    }

    public function create(array $options = []): ItemInterface
    {
        $menu = $this->factory->createItem('root');

        $menu->addChild('Home', ['route' => 'homepage']);
        $menu->addChild('Blog', ['uri' => '/posts']);
        $menu->addChild('Comments', ['uri' => '#comments']);
        $menu->addChild('Full URL', ['uri' => 'https://site.com/']);

        return $menu;
    }
}
```

After that, you can register the menu in the `config` file as shown above, or register it using `Spiral\KnpMenu\MenuRegistry`.

```
namespace App\Bootloader;

use App\Menu\Sidebar;
use Spiral\Boot\Bootloader\Bootloader;
use Spiral\KnpMenu\Bootloader\KnpMenuBootloader;
use Spiral\KnpMenu\MenuRegistry;

final class MenuBootloader extends Bootloader
{
    protected const DEPENDENCIES = [
        KnpMenuBootloader::class
    ];

    public function boot(MenuRegistry $registry, Sidebar $menu): void
    {
        $registry->add('sidebar', $menu);
    }
}
```

Using
-----

[](#using)

If you are using Twig, you can use the `knp_menu_render` extension to render the menu.

```
{{ knp_menu_render('sidebar') }}
```

With custom template or other options.

```
{{ knp_menu_render('sidebar', {'template': 'custom.twig'}) }}
```

> **Warning**To use other templating engines, need to implement the menu display mechanism yourself.

Testing
-------

[](#testing)

```
composer test
```

```
composer psalm
```

```
composer cs
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 81.3% 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 ~63 days

Total

3

Last Release

1091d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e104cad59c07d048c0b3650db8a2fde19e496e5357ee1ce1a6b3a375cade5e8a?d=identicon)[msmakouz](/maintainers/msmakouz)

---

Top Contributors

[![msmakouz](https://avatars.githubusercontent.com/u/67324318?v=4)](https://github.com/msmakouz "msmakouz (13 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")

---

Tags

knp-menumenuspiral-frameworkmenuspiralknp-menu

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/zentlix-knp-menu/health.svg)

```
[![Health](https://phpackages.com/badges/zentlix-knp-menu/health.svg)](https://phpackages.com/packages/zentlix-knp-menu)
```

###  Alternatives

[knplabs/knp-menu-bundle

This bundle provides an integration of the KnpMenu library

1.4k53.8M314](/packages/knplabs-knp-menu-bundle)[knplabs/knp-menu

An object oriented menu library

1.4k55.8M285](/packages/knplabs-knp-menu)[icings/menu

A KnpMenu seasoned menu plugin for CakePHP.

1266.4k1](/packages/icings-menu)[gourmet/knp-menu

KnpMenu for CakePHP 3

1450.7k3](/packages/gourmet-knp-menu)

PHPackages © 2026

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