- MenuComponent
- MenuHelper
Using Composer:
composer require gourmet/knp-menu:~0.4
You then need to load the plugin. In boostrap.php
, something like:
\Cake\Core\Plugin::load('Gourmet/KnpMenu');
and add the following to your App\Controller\AppController
:
public $components = ['Gourmet/KnpMenu.Menu'];
public $helpers = ['Gourmet/KnpMenu.Menu'];
It's fairly simple. The concept is you get
a menu, and you addChild
to it from anywhere at anytime at the
controller or view layer. At the view layer, you can also render any defined menu.
$menu = $this->Menu->get('my_menu');
// using an array for URL and child's name as title
$menu->addChild('Dashboard', ['uri' => ['controller' => 'Users', 'action' => 'dashboard']]);
// using a named route for URL and custom title
$menu->addChild('Dashboard', ['route' => 'dashboard', 'label' => 'My Account']);
Only available at the view layer
// by default, renders as a list
echo $this->Menu->render('my_menu');
Of course, you can set your own renderer (defaults to \Gourmet\KnpMenu\Menu\Renderer\ListRenderer
) and
matcher (defaults to \Gourmet\KnpMenu\Menu\Matcher\Matcher
) by passing them as options:
echo $this->Menu->render('my_menu', [
'matcher' => '\Custom\Matcher',
'renderer' => new \Custom\Renderer(...)
]);
For more, please check the official KnpMenu repo and documentation.
- Fork
- Mod, fix
- Test - this is important, so it's not unintentionally broken
- Commit - do not mess with license, todo, version, etc. (if you do change any, bump them into commits of their own that I can ignore when I pull)
- Pull request - bonus point for topic branches
http://github.com/gourmet/knp-menu/issues
Copyright (c) 2015, Jad Bitar and licensed under The MIT License.