Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Menu Library for PHP5

branch: master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 doc
Octocat-spinner-32 src
Octocat-spinner-32 tests
Octocat-spinner-32 .gitignore
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.markdown
Octocat-spinner-32 phpunit.xml.dist


The KnpMenu library provides object oriented menus for PHP 5.3.
It is used by the KnpMenuBundle for Symfony2 but can now be used stand-alone.


use Knp\Menu\MenuFactory;
use Knp\Menu\Renderer\ListRenderer;

$factory = new MenuFactory();
$menu = $factory->createItem('My menu');
$menu->addChild('Home', array('uri' => '/'));
$menu->addChild('Comments', array('uri' => '#comments'));
$menu->addChild('Symfony2', array('uri' => ''));
$menu->addChild('Coming soon');

$renderer = new ListRenderer()
echo $renderer->render($menu);

The above menu would render the following HTML:

  <li class="first">
    <a href="/">Home</a>
  <li class="current">
    <a href="#comments">Comments</a>
    <a href="">Symfony2</a>
  <li class="last">
    <span>Coming soon</span>

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 doc directory.


KnpMenu does not provide an autoloader but follow the PSR-0 convention. You can use any compliant autoloader for the library, for instance the Symfony2 ClassLoader component. Assuming you cloned the library in vendor/KnpMenu, it will be configured this way:

    'Knp\Menu' => __DIR__.'/vendor/KnpMenu/src'
    // ...

What now?

Follow the tutorial in doc/01-Basics-Menus.markdown and doc/02-Twig-Integration.markdown to discover how KnpMenu will rock your world!


This bundle was originally ported from ioMenuPlugin, a menu plugin for symfony1. It has since been developed by knpLabs and the Symfony community.

Something went wrong with that request. Please try again.