2017 © Pedro Peláez
 

library knp-menu-laravel

Laravel package to create navigation menus, based on KnpLabs/KnpMenu. Fork of dowilcox/KnpMenu-Laravel package

image

enimiste/knp-menu-laravel

Laravel package to create navigation menus, based on KnpLabs/KnpMenu. Fork of dowilcox/KnpMenu-Laravel package

  • Tuesday, November 22, 2016
  • by nouni.elbachir
  • Repository
  • 1 Watchers
  • 0 Stars
  • 69 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 9 Versions
  • 0 % Grown

The README.md

KnpMenu-Laravel

Laravel 5 package to create navigation menus, based on KnpLabs/KnpMenu., (*1)

Installation

Add to your composer.json file, (*2)

"enimiste/knp-menu-laravel": "2.*"

Register the package

In config/app.php add the service provider and alias., (*3)

Dowilcox\KnpMenu\MenuServiceProvider::class,
'Menu' => Dowilcox\KnpMenu\Facades\Menu::class,

To Access the menu service directly :, (*4)

$menu_builder = app('knp_menu.menu');

Publish config

php artisan vendor:publish --tag=knp_menu

Custom Rendrer

To define your custom renderer :
- Implements the interface "Knp\Menu\Renderer\RendererInterface" - Register a binding to "knp_menu.renderer" that returns a new instance of your new custom renderer. To get the matcher use $app["knp_menu.matcher"], (*5)

Custom Voter

To add custom Voter you implement the interface "Dowilcox\KnpMenu\Voter\OrderedVoterInterface" and register it in the service container with the tag "knp_menu.voter"
Set the lower order for Voter that should be executed in first.
It is recommended order values between 0 and than 100.
Your Voters will be executed first before the built in ones.
- RouteNameVoter (100) - UriVoter (200 and 300), (*6)

Blade directives

  • @rendermenu("main" [, {"firstClass":"first2","lastClass":"last2"}]) or @rendermenu("main" [, "config_name"]): It renders the menu defined by the name "menu_name". It is a shortcut to echo \Menu::render(\Menu::get('menu_name'))
  • @menu('menu_name') .... @endmenu : between these two directives you have access to a variable named $menu holding the menu defined by the name "menu_name". This object is an instance of Knp\Menu\MenuItem

Example

$menu = Menu::create('main-menu', ['childrenAttributes' => ['class' => 'nav']]);

/*
* This is the list of possible options for a menu item :
*
*     'uri' => null,
*     'label' => null,
*     'attributes' => array(),
*     'linkAttributes' => array(),
*     'childrenAttributes' => array(),
*     'labelAttributes' => array(),
*     'extras' => array(),
*     'current' => null,
*     'display' => true,
*     'displayChildren' => true,
*/

$menu->addChild('Home', [
'uri' => url('/'),
'attributes' => [
    'class'=>'your_css_class',
 ],
 'extras' => [
    'routes' => [
        ['route' => 'route_name_1'],
        ['route' => 'route_name_2'],
    ]
 ]
]);
$menu->addChild('Users', ['uri' => route('admin.users.index')]);
$menu->addChild('Roles', ['uri' => route('admin.roles.index')]);
$menu->addChild('Menu', ['uri' => url('menu')]);

echo Menu::render($menu);
//Or
echo Menu::render($menu, $custom_render_options);//$custom_render_options is an array

Will output:, (*7)

<ul class="nav">
  <li class="first">
    <a href="http://localhost:8000">Home</a>
  </li>
  <li class='your_css_class'>
    <a href="http://localhost:8000/admin/users">Users</a>
  </li>
  <li class='your_css_class'>
    <a href="http://localhost:8000/admin/roles">Roles</a>
  </li>
  <li class="current active last your_css_class">
    <a href="http://localhost:8000/menu">Menu</a>
  </li>
</ul>

The Versions

22/11 2016

dev-master

9999999-dev

Laravel package to create navigation menus, based on KnpLabs/KnpMenu. Fork of dowilcox/KnpMenu-Laravel package

  Sources   Download

MIT

The Requires

 

The Development Requires

by El bachir NOUNI

22/11 2016

2.2.2

2.2.2.0

Laravel package to create navigation menus, based on KnpLabs/KnpMenu. Fork of dowilcox/KnpMenu-Laravel package

  Sources   Download

MIT

The Requires

 

The Development Requires

by El bachir NOUNI

22/11 2016

2.2.1

2.2.1.0

Laravel package to create navigation menus, based on KnpLabs/KnpMenu. Fork of dowilcox/KnpMenu-Laravel package

  Sources   Download

MIT

The Requires

 

The Development Requires

by El bachir NOUNI

21/11 2016

2.2.0

2.2.0.0

Laravel package to create navigation menus, based on KnpLabs/KnpMenu. Fork of dowilcox/KnpMenu-Laravel package

  Sources   Download

MIT

The Requires

 

The Development Requires

by El bachir NOUNI

20/11 2016

2.1.0

2.1.0.0

Laravel package to create navigation menus, based on KnpLabs/KnpMenu. Fork of dowilcox/KnpMenu-Laravel package

  Sources   Download

MIT

The Requires

 

The Development Requires

by El bachir NOUNI

19/11 2016

2.0.1

2.0.1.0

Laravel package to create navigation menus, based on KnpLabs/KnpMenu. Fork of dowilcox/KnpMenu-Laravel package

  Sources   Download

MIT

The Requires

 

The Development Requires

by El bachir NOUNI

09/06 2015

1.0.1

1.0.1.0

Laravel package to create navigation menus, based on KnpLabs/KnpMenu.

  Sources   Download

MIT

The Requires

 

The Development Requires

13/03 2015

1.0.0

1.0.0.0

Laravel package to create navigation menus, based on KnpLabs/KnpMenu.

  Sources   Download

MIT

The Requires

 

The Development Requires

03/03 2015

0.0.1

0.0.1.0

Laravel package to create navigation menus, based on KnpLabs/KnpMenu.

  Sources   Download

MIT

The Requires