kalamu/menu-service-bundle
Composer 安装命令:
composer require kalamu/menu-service-bundle
包简介
Service to provide knp menu by configuration
README 文档
README
This bundle provide a menu service for knp/menu-bundle that is configurable by config file.
Installation
composer require kalamu/menu-service-bundle:^2.0
Puis ajouter dans AppKernel.php
public function registerBundles() { $bundles = array( ... new Knp\Bundle\MenuBundle\KnpMenuBundle(), new Kalamu\MenuServiceBundle\KalamuMenuServiceBundle(), ); }
How to build a menu
To build a menu, you just have to add the items in your app/config/config.yml file :
kalamu_menu_service: menu_name: items: - {label: "Home", route: home_route, icon: '<i class="fa fa-home"></i>' } - {label: "Item 1", route: item1_route, icon: '<i class="fa fa-gear"></i>' } ...
Then, to add the menu in the template :
<div class="my_menu"> {{knp_menu_render('menu_name', {'allow_safe_labels': true})}} </div>
Security
Restrict access by roles
The roles option allow to control if an item is available to an user depending
on his authorizations. This option take an array of roles. The user must be
authorized for each of theses roles to see the item.
Example:
kalamu_menu_service: menu_name: items: - {label: "Home", route: home_route, icon: '<i class="fa fa-home"></i>', roles: ['ROLE_USER', 'ROLE_OPEN_DOOR'] }
To access the home item, the user must have both roles ROLE_USER and
ROLE_OPEN_DOOR.
Restrict access by expression
The 'allow_if' option provide a more customizable way to handle the restrictions. The option take an expression as argument. For more information about the syntax, see the documentation about How to use Expressions in Security.
Example:
kalamu_menu_service: menu_name: items: - {label: "Home", route: home_route, icon: '<i class="fa fa-home"></i>', allow_if: "has_role('ROLE_USER') or has_role('ROLE_OPEN_DOOR')" }
To access the Home item, the user must have either the role ROLE_USER or
the role ROLE_OPEN_DOOR.
The option roles can be used in combination with the allow_if options.
In such case, both constraints must be satisfied to grant access.
Restrict access by hierarchy
On a menu with hierarchical items, most of the time the parent item has no sens without his children. So it must be removed if all children are not accessible to the current user.
If there is only a few underlying roles, this could be handled with the allow_if
option. But if the number of constraints grow, the task become uselessly
cumbersome.
The hide_if_no_child option solve this problem. If set to true, the item is
available only if the user has access to at least one child.
Example:
kalamu_menu_service: menu_name: items: - label: "User management" route: '' hide_if_no_child: true items: - {label: "Users", route: user_list, roles: ['ROLE_MANAGE_USER'] } - {label: "Groups", route: group_list, allow_if: '(user and user.isSuperAdmin())) or user.isGoodManager()' }
Customisation
If you want to change interactivly you menu, you can use the events kalamu.menu_service.configure.{menu_name}.
For more informations on knp/menu-bundle : https://github.com/KnpLabs/KnpMenuBundle/blob/master/Resources/doc/events.md#create-a-listener
kalamu/menu-service-bundle 适用场景与选型建议
kalamu/menu-service-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.78k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2016 年 07 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 kalamu/menu-service-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kalamu/menu-service-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.78k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 3
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-07-07