gpt4 book ai didi

symfony - 如何使用 KNP Menu Bundle 2 创建面包屑?

转载 作者:行者123 更新时间:2023-12-02 13:47:41 24 4
gpt4 key购买 nike

所以我构建了一个菜单,如下例所示:

<?php namespace AppBundle\Menu;

use Doctrine\ORM\EntityManager;
use Knp\Menu\FactoryInterface;
use Knp\Menu\MenuFactory;

class AdminMenuBuilder
{

public function sidebarMenu(FactoryInterface $factory, array $options)
{
$menu = $factory->createItem('root', array(
'navbar' => true,
'childrenAttributes' => [
'class' => 'nav main-menu',
],
));


$menu->addChild('Dashboard')
->setAttributes([
'icon' =>'fa fa-dashboard',
'class' => 'dropdown',
'dropdown' => true
]);

$menu['Dashboard']->addChild('Details', ['route' => 'app.admin.dashboard']);
$menu['Dashboard']->addChild('Details 2', ['route' => 'app.admin.dashboard']);

$menu->addChild('Users', ['route' => 'app.admin.dashboard.users'])
->setAttribute('icon', 'fa fa-users');


return $menu;
}
}

如何使用 KNPMenuBundle v2 创建面包屑?我正在使用 symfony2 2.7.5

最佳答案

KnpMenuBundle 2.1.0(几周前发布)有一个 knp_menu_get_breadcrumbs_array() 函数可供您使用。例如:

{% set item = knp_menu_get('some_menu_item') %}
{% set breadcrumbs = knp_menu_get_breadcrumbs_array(item) %}
{% for breadcrumb in breadcrumbs %}
<a href="{{ breadcrumb.url }}">{{ breadcrumb.label }}</a>
{% endfor %}

关于symfony - 如何使用 KNP Menu Bundle 2 创建面包屑?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33046129/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com