Skip to content
Menu Library for PHP5
PHP HTML
Branch: master
Clone or download

Latest commit

ndm2 Fix `currentAsLink` not working when determining state via voters. (#328
)

The renderer was checking the items "current" state using its
`isCurrent()` method instead of the matcher, hence it would only work
when the state was manually set on the item via its `setCurrent()`
method.
Latest commit 254fb64 Apr 22, 2020

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
doc minor fix Oct 4, 2019
src/Knp/Menu Fix `currentAsLink` not working when determining state via voters. (#328 Apr 22, 2020
tests/Knp/Menu/Tests Fix `currentAsLink` not working when determining state via voters. (#328 Apr 22, 2020
.gitattributes fixed wrong folder and file name Jan 30, 2019
.gitignore Switched the testsuite to composer May 8, 2012
.travis.yml do not allow failure on php 7.4 Dec 1, 2019
CHANGELOG.md prepare release v3.1.0 Dec 1, 2019
CODE_OF_CONDUCT.md created code of conduct Feb 14, 2020
LICENSE Use missing depth argument in isAncestor method Aug 23, 2017
README.markdown Fix documentation links Nov 20, 2019
composer.json prepare release v3.1.0 Dec 1, 2019
phpunit.xml.dist Improve the testsuite and the CI setup Sep 20, 2015

README.markdown

KnpMenu

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

Build Status Latest Stable Version Latest Unstable Version Gitter chat

Installation

KnpMenu uses Composer, please checkout the composer website for more information.

The simple following command will install knp-menu into your project. It also add 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-menu classes 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 doc directory.

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

  • @derrabus
  • @garak
  • @stof

Credits

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

You can’t perform that action at this time.