appaydin/pd-menu
Composer 安装命令:
composer require appaydin/pd-menu
包简介
Symfony Simple Menu Bundle
README 文档
README
Simple fast object-oriented menu maker for Symfony 5
Installation
Step 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 appaydin/pd-menu
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Step 2: Enable the Bundle
With Symfony 4, the package will be activated automatically. But if something goes wrong, you can install it manually.
Then, enable the bundle by adding it to the list of registered bundles
in the config/bundles.php file of your project:
<?php // config/bundles.php return [ //... Pd\MenuBundle\PdMenuBundle::class => ['all' => true] ];
Create Your First menu
Step 1: Without Service
You can create menus without service. You can load the necessary parameters using $options
<?php // src/Menu/FirstMenu.php namespace App\Menu; use Pd\MenuBundle\Builder\ItemInterface; use Pd\MenuBundle\Builder\Menu; class FirstMenu extends Menu { /** * Override */ public function createMenu(array $options = []): ItemInterface { // Create Root Item $menu = $this ->createRoot('settings_menu', true) // Create event is "settings_menu.event" ->setChildAttr(['data-parent' => 'admin_account_list']); // Add Parent Menu to Html Tag // Create Menu Items $menu->addChild('nav_config_general', 1) ->setLabel('nav_config_general') ->setRoute('admin_settings_general') ->setLinkAttr(['class' => 'nav-item']) ->setRoles(['ADMIN_SETTINGS_GENERAL']) // Contact ->addChildParent('nav_config_contact', 5) ->setLabel('nav_config_contact') ->setRoute('admin_settings_contact') ->setLinkAttr(['class' => 'nav-item']) ->setRoles(['ADMIN_SETTINGS_CONTACT']) // Email ->addChildParent('nav_config_email', 10) ->setLabel('nav_config_email') ->setRoute('admin_settings_email') ->setLinkAttr(['class' => 'nav-item']) ->setRoles(['ADMIN_SETTINGS_EMAIL']) // Template ->addChildParent('nav_config_template') ->setLabel('nav_config_template') ->setRoute('admin_settings_template') ->setLinkAttr(['class' => 'nav-item']) ->setRoles(['ADMIN_SETTINGS_TEMPLATE']) // Account ->addChildParent('nav_config_user') ->setLabel('nav_config_user') ->setRoute('admin_settings_user') ->setLinkAttr(['class' => 'nav-item']) ->setRoles(['ADMIN_SETTINGS_USER']); return $menu; } }
Rendering Menu
The creation process is very simple. You can specify additional options.
{{ pd_menu_render('App\\Menu\\FirstMenu', {
'custom': 'variable or options'
}) }}
You can change the default options.
{{ pd_menu_render('App\\Menu\\FirstMenu', {
'template': '@PdMenu/Default/menu.html.twig',
'depth': null,
'currentClass': 'active',
'trans_domain': 'admin',
'iconTemplate' => '<i class="material-icons">itext</i>'
}) }}
You can change the default options globally.
config/packages/pd_menu.yaml
pd_menu:
template: '@PdMenu/Default/menu.html.twig',
depth: null,
currentClass: active
trans_domain: admin,
iconTemplate: '<i class="fa&text"></i>'
Create Menu Event & Event Listener
Step 1: Create Menu Event
All menus automatic events are generated. Example : "menu_name.event"
Step 2: Create Menu Listener
Now let's create a listener for the event.
<?php // src/Listener/MenuListener.php namespace App\Listener; use Pd\MenuBundle\Event\PdMenuEvent; class MenuListener { public function onCreate(PdMenuEvent $event) { // Get Menu Items $menu = $event->getMenu(); // Add New Item $menu->addChild('demo_item', 5) ->setLabel('Home Page') ->setRoute('home_route'); } }
Let's create a service for the listener.
App\Menu\MenuListener: tags: - { name: kernel.event_listener, event: settings_menu.event, method: onCreate }
appaydin/pd-menu 适用场景与选型建议
appaydin/pd-menu 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.32k 次下载、GitHub Stars 达 15, 最近一次更新时间为 2018 年 10 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「menu」 「symfony-menu」 「pd-admin」 「pd-menu」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 appaydin/pd-menu 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 appaydin/pd-menu 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 appaydin/pd-menu 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Symfony extension to get active class base on current bundle/controller/action
Symfony Simple User Bundle
Symfony Simple Widget Bundle
Symfony Activity Log Bundle
Symfony Restful Api Bundle
Yii2 DynaTree Menu widget uses Dynamic tree view control jquery.dynatree.js
统计信息
- 总下载量: 3.32k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 15
- 点击次数: 2
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-10-29