eschmar / menu-bundle
为Symfony设计的简单面向对象的菜单。
v1.0.0
2019-02-20 21:39 UTC
Requires
- php: >=7.1.0
- symfony/security: 4.2.*
- symfony/security-bundle: 4.2.*
This package is auto-updated.
Last update: 2024-09-11 19:59:33 UTC
README
为Symfony提供带有角色权限的简单面向对象菜单。
安装
Composer (Packagist)
composer require eschmar/menu-bundle ^1.0.0 # Symfony 4
查看eschmar/menu-bundle ^0.2.0
以了解Symfony 3的安装。
使用方法
为你的每个菜单创建一个新的<Name>Menu
类,继承自AbstractMenu
,并放置在App\Menu
命名空间下
namespace App\Menu; use Eschmar\MenuBundle\Menu\AbstractMenu; class TestMenu extends AbstractMenu { public function generateMenu() { // create root node $this->root = $this->newNode('Navigation'); // append a new node for each navigation element $this->root->node('Link 1'); $this->root->node('Link 2'); $this->root->node('Link 3'); // multi-dimensional $this->root['Link 2']->node('Sublink 1'); $this->root['Link 2']['Sublink 1']->node('Subsublink 1'); // generate route $this->root['Link 3']->node('Sublink 3', null, 'acme_hello_homepage'); // role permissions $this->root['Link 3']->node('Sublink 2', null, null, 'ROLE_ADMIN', array()); } } // END class TestMenu
直接在twig中渲染菜单
{{ menu('TestMenu') }} {# override template #} {{ menu('TestMenu', 'test/mobile.html.twig') }} ``` # License MIT License.