knplabs/knp-menu
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
The "knplabs/knp-menu" is an object-oriented PHP library for creating menus. This powerful framework is designed to simplify the process of creating dynamic and structured menus. Originally ported from ioMenuPlugin, a menu plugin for Symfony1, "knplabs/knp-menu" is now a stand-alone package that can be used outside the Symfony ecosystem as well. As a testament to its versatility and robustness, it is still used by KnpMenuBundle for Symfony.
To use "knplabs/knp-menu", begin by installing the package using Composer. Open your terminal and run:
$ composer require knplabs/knp-menu
Next, integrate "knp-menu" into your PHP project with the following code:
<?php
// Include dependencies installed with composer
require 'vendor/autoload.php';
use Knp\Menu\MenuFactory;
use Knp\Menu\Renderer\ListRenderer;
// Creating a menu
$factory = new MenuFactory();
$menu = $factory->createItem('My menu');
// Adding items to the 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());
// Render the menu
echo $renderer->render($menu);
You now have a simple functional menu. But, that's just the basic use. "knplabs/knp-menu" provides more flexible options allowing you to create more complex menus including sub-menus.
The official documentation for "knplabs/knp-menu" resides in the doc
directory of the project's GitHub repository. A comprehensive tutorial detailing how to efficiently make the most of "knp-menu" can be found in doc/01-Basic-Menus.md
and doc/02-Twig-Integration.md
within the documentation directory. An assortment of practical examples, supplementary resources, and advanced usage instructions can also be found throughout the doc
directory.