定制 fgc/menu-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 fgc/menu-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 131
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-09-28