agence-adeliom/easy-menu-bundle

EasyAdmin 的 Symfony 菜单包

2.0.122 2024-05-29 09:45 UTC

README

Adeliom Quality gate

Easy Menu Bundle

Easyadmin 的基本菜单系统。

版本

使用 Symfony Flex 安装

添加我们的配方端点

{
  "extra": {
    "symfony": {
      "endpoint": [
        "https://api.github.com/repos/agence-adeliom/symfony-recipes/contents/index.json?ref=flex/main",
        ...
        "flex://defaults"
      ],
      "allow-contrib": true
    }
  }
}

使用 composer 安装

composer require agence-adeliom/easy-menu-bundle

启用树扩展

更新 config/packages/stof_doctrine_extensions.yaml 以添加 gedmo tree 映射配置

stof_doctrine_extensions:
  orm:
    default:
      tree: true
      
doctrine:
  orm:
    entity_managers:
      default:
        mappings:
          gedmo_tree:
            type: attribute
            prefix: Gedmo\Tree\Entity
            dir: "%kernel.project_dir%/vendor/gedmo/doctrine-extensions/src/Tree/Entity"
            alias: GedmoTree # (optional) it will default to the name set for the mapping
            is_bundle: false

设置数据库

使用 doctrine 迁移

php bin/console doctrine:migration:diff
php bin/console doctrine:migration:migrate

不使用

php bin/console doctrine:schema:update --force

文档

在您的 Easyadmin 控制台中管理菜单

前往您的仪表盘控制器,例如: src/Controller/Admin/DashboardController.php

<?php

namespace App\Controller\Admin;

...
use App\Entity\EasyMenu\Menu;

class DashboardController extends AbstractDashboardController
{
    ...
    public function configureMenuItems(): iterable
    {
        ...
        yield MenuItem::linkToCrud('easy.menu.admin.menus', 'fa fa-file-alt', Menu::class);

        ...

在前端页面中添加菜单(使用 twig)

# 1. Create as separate html twig file to render your template :
templates/bundles/EasyMenuBundle/front/menus/my_menu_code.html.twig

# 2. Execute this twig extension on your controller template
{{ easy_menu('my_menu_code') }}

# Optional. If you need to specify your own template file path
{{ easy_menu('my_menu_code', { 'template': 'menus/my_menu_code.html.twig' }) }}

在您的菜单模板中,您可以列出菜单项

<ul>
    {% for item in menu.items %}
        <li>{{ item.name }}</li>
        {# recursive loop ... #}
    {% endfor %}
</ul>

许可证

MIT

作者