fgc/menu-bundle
Composer 安装命令:
composer require fgc/menu-bundle
包简介
A simple yet robust menu generator for Symfony4
README 文档
README
The FGCMenuBundle is a simple yet robust menu renderer for Symfony4.
The biggest change is the decision to remove Annotation Support. The feature made code handling difficult to manage, and chasing down menu items difficult. So centralising menu creation in configurations, and events.
Documentation
Installation
1. Download the bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require fgc/menu-bundle
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
2. Enable the Bundle
Then, enable the bundle by adding the following line in the app/AppKernel.php file of your project:
This is only needed if you don't have symfony/flex.
// config/bundles.php // ... return [ // ... FGC\MenuBundle\FGCMenuBundle::class => ['all' => true], ];
3. Configure the bundle
The bundle comes with a sensible default configuration, which is listed below. You can define these options if you need to change them:
# config/packages/fgc_menu.yaml fgc_menu: # Menu group name and identifier # default is also the group given if omitted default: # Menu Title Home Page: # each option below is optional # route name for the link to generate route: homepage # route parameters if any. If omitted, an empty array is returned routeOptions: option: value option2: value # icon to be attached to the menu item. Great for dashboards icon: dashboard # order of the items, so inserted Items during events can be integrated smoothly order: 1 # a single ROLE to show only if is_granted() or none to always show This was previously ROLE, and is a # breaking change. granted: IS_ANONYMOUS # This is needed if the granted action needs an object to check against. You may need to dynamically add # the menu item to add objects rather than strings grantedObject: 'User' # to make mult-level menus, menu name to place under this item. children: user
Add Dynamic Menu Items
Follow the instructions to make
an event subscriber and listen for the DiscoverMenuEvent::NAME event.
Here, you can $event->addMenuItem(Menu) on the fly.
Make sure to remember to add group names.
And lastly:
Render the menus in your templates.
{# ... #} {{ fgc_menu() }} {# ... #}
This renders:
<li> <a href="/"> Home </a> </li> <li> <a href="/admin/"> Admin Area </a> </li>
And can be modified with additional parameters.
{{ fgc_menu("Menu Group Name", "template name", (int)depth) }}
Templating the menu
I have a few templates I have needed already.
- default
- bootstrap4
- sb_admin_2
There are more coming, and can easily be overridden by adding them to your app/Resources directory.
{# templates/bundles/FGCMenuBundle/{template_name}.html.twig #} {% for item in menu %} {% if not item.granted or is_granted(item.granted, item.grantedObject) %} <li> <a href="{{ item.route ? path(item.route, item.routeOptions) : '#' }}"> {% if item.icon %}<i class="fa fa-{{ item.icon }}" ></i>{% endif %} {{ item.name }} </a> {% if item.children and depth %} <ul> {{ fgc_menu(item.children, template, depth) }} </ul> {% endif %} </li> {% endif %} {% endfor %}
Afterword
In v2, cache was attempted to be added, and while it saved the cache correctly, there are too many variables to chase down into to generate the cache key. I may try again, but not now.
Please feel free to submit issues so it can be improved.
fgc/menu-bundle 适用场景与选型建议
fgc/menu-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 131 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 09 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「menu」 「Simple」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fgc/menu-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fgc/menu-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fgc/menu-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Symfony extension to get active class base on current bundle/controller/action
The bundle for easy using json-rpc api on your project
A simple library for make Lexer and Parsers to build a language
A simple library that allows transform any kind of data to native php data or whatever
A simple library that uses the hydration pattern to fill objects given different sources of data.
Micro Active Record library in PHP, support chain calls, events, and relations.
统计信息
- 总下载量: 131
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-09-28