converia / config-knp-menu-bundle
v4.2.3
2020-01-07 12:43 UTC
Requires
- knplabs/knp-menu-bundle: ^2.0
- symfony/event-dispatcher: ^4.0
- symfony/security-bundle: ^4.0
- symfony/yaml: ^4.0
Requires (Dev)
- phpunit/phpunit: ~5.0
- squizlabs/php_codesniffer: ~2.5
This package is not auto-updated.
Last update: 2020-01-07 12:51:07 UTC
README
包已弃用 - 使用 jbouzekri/config-knp-menu-bundle
代替
===================
简介
此包提供了一种在您的包yml配置中配置knp菜单的方式。
有关knp菜单的更多信息,请参阅
此包受到了oro crm中的OroNavigationBundle的启发。
安装
您可以使用composer进行安装。
将仓库添加到项目的composer.json文件中,并运行更新或安装命令。
{ "require": { "converia/config-knp-menu-bundle": "^4.2" } }
然后在AppKernel.php中启用KnpMenuBundle
$bundles = array( ... new Knp\Bundle\MenuBundle\KnpMenuBundle(), new Jb\Bundle\ConfigKnpMenuBundle\JbConfigKnpMenuBundle(), );
文档
为了使用此包,您必须在包中的navigation.yml文件中定义您的菜单配置。
示例
my_mega_menu: tree: first_level_item: label: My first label children: second_level_item: label: My second level
这将配置一个用于knp菜单工厂的提供者。然后您可以在twig中使用my_mega_menu作为经典的knp菜单
{{ knp_menu_render('my_mega_menu') }}
配置
这是可用的项目配置定义。
my_mega_menu: childrenAttributes: An array of attributes passed to the root ul tag tree: first_level_item: uri: "An uri. Use it if you do not define route parameter" route: "A sf2 route without @" routeParameters: "an array of parameters to pass to the route" label: "My first label" order: An integer to sort the item in his level. attributes: An array of attributes passed to the knp item linkAttributes: An array of attributes passed to the a tag childrenAttributes: An array of attributes passed to the chidlren block labelAttributes: An array of attributes passed to the label tag display: boolean to hide the item displayChildren: boolean to hide the children roles: array of item (string roles) passed to isGranted securityContext method to check if user has rights in menu items extras: An array of extra parameters (for example icon img, additional content etc.) children: # An array of subitems second_level_item: label: My second level
此配置与Knp Menu Item类中可用的方法匹配
菜单安全
安全上下文被注入到菜单项提供者中。
对于根菜单项,在您的twig模板中显示或隐藏它。对于子菜单项,如果您没有添加roles键,它们将显示出来。否则,它将传递键数组到isGranted方法,并检查您是否有权限访问该项。
问题
- tree子配置属性:在navigation.yml文件中,您必须在菜单名称下定义一个tree键。它在解析配置后提供另一个级别以保留第一级项目键。如果有人知道如何删除它,请告诉我。