KnpLabs/KnpMenu
KnpLabs/KnpMenu has 1,397 GitHub stars and 186 forks. GitHot measured 0 stars in 24 hours. Last checked 2026-11-08 06:08 UTC. Last push 2026-08-21.
Menu Library for PHP
Measured star growth
- in 24h
- 0
- in 7 days
- Collecting history
- in 15 days
- Collecting history
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
OriginalKnpMenu
The KnpMenu library provides object-oriented menus for PHP. It is used by the KnpMenuBundle for Symfony but can now be used stand-alone.
Installation
KnpMenu uses Composer, please check out the composer website for more information.
The simple following command will install knp-menu into your project. It also adds a new
entry in your composer.json and update the composer.lock as well.
composer require knplabs/knp-menu
KnpMenu follows the PSR-4 convention names for its classes, which means you can easily integrate
knp-menuclasses loading in your own autoloader.
Getting Started
<?php
// Include dependencies installed with composer
require 'vendor/autoload.php';
use Knp\Menu\MenuFactory;
use Knp\Menu\Renderer\ListRenderer;
$factory = new MenuFactory();
$menu = $factory->createItem('My menu');
$menu->addChild('Home', ['uri' => '/']);
$menu->addChild('Comments', ['uri' => '#comments']);
$menu->addChild('Symfony', ['uri' => 'http://symfony.com/']);
$menu->addChild('Happy Awesome Developers');
$renderer = new ListRenderer(new \Knp\Menu\Matcher\Matcher());
echo $renderer->render($menu);
The above menu would render the following HTML:
<ul>
<li class="first">
<a href="/">Home</a>
</li>
<li class="current">
<a href="#comments">Comments</a>
</li>
<li>
<a href="http://symfony.com/">Symfony</a>
</li>
<li class="last">
<span>Happy Awesome Developers</span>
</li>
</ul>
This way you can finally avoid writing an ugly template to show the selected item, the first and last items, submenus, ...
The bulk of the documentation can be found in the
docdirectory.
What now?
Follow the tutorial in doc/01-Basic-Menus.md and doc/02-Twig-Integration.md
to discover how KnpMenu will rock your world!
Find all available documentation at doc/.
Maintainers
This library is maintained by the following people (alphabetically sorted) :
Credits
This bundle was originally ported from ioMenuPlugin, a menu plugin for symfony1. It has since been developed by KnpLabs and the Symfony community.
Explore related projects
codecrafters-io/build-your-own-x
Master programming by recreating your favorite technologies from scratch.
560,973 starspublic-apis/public-apis
A collective list of free APIs
497,232 starsmorluto/rea
Reverse engineer anything with agents, from app behavior down to native binaries.
442,848 starsopenclaw/openclaw
The AI that really does things. Any OS. Any Platform. The lobster way. 🦞
394,187 stars