firestorm23/config-knp-menu-bundle

jbouzekri/ConfigKnpMenuBundle 的分支

安装: 15

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 12

类型:symfony-bundle

3.0.0 2014-10-24 21:44 UTC

This package is not auto-updated.

Last update: 2024-09-18 17:07:17 UTC


README

Build Status

简介

此捆绑包提供了一种在您的捆绑包 yml 配置中配置 knp 菜单的方法。

有关 knp 菜单的更多信息,请参阅

此捆绑包受到 oro crm 中的 OroNavigationBundle 的启发。

安装

您可以使用 composer 进行安装。

将仓库添加到您项目的 composer.json 文件中,然后运行更新或安装命令。

{
    "require": {
        "jbouzekri/config-knp-menu-bundle": "3.0.0"
    }
}

然后在您的 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
            children: # An array of subitems
                second_level_item:
                    label: My second level

此配置与 Knp 菜单项类中可用的方法相匹配

菜单安全

安全上下文被注入到菜单项提供者中。

对于根菜单项,在您的 twig 模板中显示或隐藏它。对于子项,如果您没有添加 roles 键,则将显示它们。否则,它将传递键数组到 isGranted 方法中,并检查您是否有权访问该项。

问题

  • tree 子配置属性:在 navigation.yml 文件中,您必须在菜单名称下定义一个 tree 键。它在解析配置后提供另一个级别来保留第一级项键。如果有人知道如何删除它,请告诉我。