enimiste/knp-menu-laravel
Composer 安装命令:
composer require enimiste/knp-menu-laravel
包简介
Laravel package to create navigation menus, based on KnpLabs/KnpMenu. Fork of dowilcox/KnpMenu-Laravel package
README 文档
README
Laravel 5 package to create navigation menus, based on KnpLabs/KnpMenu.
Installation
Add to your composer.json file
"enimiste/knp-menu-laravel": "2.*"
Register the package
In config/app.php add the service provider and alias.
Dowilcox\KnpMenu\MenuServiceProvider::class,
'Menu' => Dowilcox\KnpMenu\Facades\Menu::class,
To Access the menu service directly :
$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"]
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)
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
$menuholding the menu defined by the name "menu_name". This object is an instance ofKnp\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:
<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>
enimiste/knp-menu-laravel 适用场景与选型建议
enimiste/knp-menu-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 647 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 11 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 enimiste/knp-menu-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 enimiste/knp-menu-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 647
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-11-19