tourze/easy-admin-menu-bundle
Composer 安装命令:
composer require tourze/easy-admin-menu-bundle
包简介
EasyAdmin 菜单管理组件,提供灵活的菜单配置和管理功能
README 文档
README
A Symfony bundle for simplified menu management in EasyAdmin backend systems. This bundle provides easy-to-use tools for organizing menus and generating admin links.
Table of Contents
- Features
- Requirements
- Installation
- Configuration
- Quick Start
- Advanced Usage
- API Reference
- Testing
- Contributing
- License
Features
- Simplified menu organization and management
- Attribute-based menu provider registration with
#[MenuProvider] - Easy link generation for EasyAdmin CRUD pages
- Entity class extraction from URLs
- Integration with KnpMenuBundle for menu rendering
- Automatic service configuration and DI
Requirements
- PHP 8.1 or higher
- Symfony 6.4 or higher
- EasyAdmin Bundle 4.x
- KnpMenuBundle 3.7 or higher
Installation
Install the bundle using Composer:
composer require tourze/easy-admin-menu-bundle
The bundle will be automatically registered if you're using Symfony Flex.
Otherwise, add it manually to config/bundles.php:
// config/bundles.php return [ // ... Tourze\EasyAdminMenuBundle\EasyAdminMenuBundle::class => ['all' => true], ];
Configuration
The bundle works out of the box with default configuration. No additional configuration is required for basic usage.
Custom Menu Factory
You can customize the menu factory by defining your own service:
# config/services.yaml services: easy-admin-menu.factory: class: Knp\Menu\MenuFactory # Add your custom configuration here
Quick Start
1. Create a Menu Provider
Create a menu provider class and mark it with the #[MenuProvider] attribute:
<?php namespace App\Menu; use Knp\Menu\ItemInterface; use Tourze\EasyAdminMenuBundle\Attribute\MenuProvider; use Tourze\EasyAdminMenuBundle\Service\MenuProviderInterface; #[MenuProvider] class MainMenuProvider implements MenuProviderInterface { public function __invoke(ItemInterface $item): void { $item->addChild('Dashboard', [ 'route' => 'admin_dashboard' ]); $item->addChild('Users', [ 'route' => 'admin', 'routeParameters' => [ 'crudAction' => 'index', 'crudControllerFqcn' => UserCrudController::class ] ]); } }
2. Generate Admin Links
Use the LinkGeneratorInterface to generate EasyAdmin CRUD links:
<?php namespace App\Controller; use App\Entity\User; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Tourze\EasyAdminMenuBundle\Service\LinkGeneratorInterface; class DashboardController extends AbstractController { public function __construct( private readonly LinkGeneratorInterface $linkGenerator, ) { } public function index() { // Generate list page URL for User entity $userListUrl = $this->linkGenerator->getCurdListPage(User::class); // Extract entity class from URL $someUrl = 'https://example.com/admin?crudControllerFqcn=App\\Controller\\Admin\\UserCrudController'; $entityClass = $this->linkGenerator->extractEntityFqcn($someUrl); // Result: App\Entity\User (if UserCrudController has getEntityFqcn() method) return $this->render('dashboard/index.html.twig', [ 'userListUrl' => $userListUrl, ]); } }
3. Collect and Render Menus
The bundle automatically collects all menu providers and makes them available
through the MenuCollectorInterface:
<?php namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Tourze\EasyAdminMenuBundle\Service\MenuCollectorInterface; class MenuController extends AbstractController { public function __construct( private readonly MenuCollectorInterface $menuCollector, ) { } public function mainMenu() { $menu = $this->menuCollector->mainMenu($this->getUser()); return $this->render('menu/main.html.twig', [ 'menu' => $menu, ]); } }
Advanced Usage
Multiple Menu Providers
You can create multiple menu providers for different sections:
#[MenuProvider] class AdminMenuProvider implements MenuProviderInterface { public function __invoke(ItemInterface $item): void { $item->addChild('Admin Section', ['uri' => '#']) ->addChild('Users', ['route' => 'admin_users']) ->addChild('Settings', ['route' => 'admin_settings']); } } #[MenuProvider] class ContentMenuProvider implements MenuProviderInterface { public function __invoke(ItemInterface $item): void { $item->addChild('Content', ['uri' => '#']) ->addChild('Articles', ['route' => 'admin_articles']) ->addChild('Categories', ['route' => 'admin_categories']); } }
API Reference
LinkGeneratorInterface
getCurdListPage(string $entityClass): string- Generate CRUD list page URL for an entityextractEntityFqcn(string $url): ?string- Extract entity FQCN from admin URL
MenuProviderInterface
__invoke(ItemInterface $item): void- Add menu items to the root menu
MenuCollectorInterface
mainMenu(?UserInterface $user = null): ItemInterface- Collect and return the main menu
Testing
Run the test suite:
./vendor/bin/phpunit packages/easy-admin-menu-bundle/tests
Contributing
Please see CONTRIBUTING.md for details on how to contribute to this project.
License
The MIT License (MIT). Please see License File for more information.
tourze/easy-admin-menu-bundle 适用场景与选型建议
tourze/easy-admin-menu-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20.22k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 04 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 tourze/easy-admin-menu-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tourze/easy-admin-menu-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 20.22k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 19
- 依赖项目数: 173
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-22