1
votes

I use stable versions of KnpMenu and KnpMenuBundle - v.1.2.0 I can't use v.2, because of some dependencies.

And I'm trying to build breadcrumbs, depending on my menu.

Let's start with menu. I have my MenuBuilder class:

$menu = $this->factory->createItem('main');
$menu->setLabel('Main');
$menu->addChild('home', array('route' => 'home','label'=>'Home'));
$menu['home']->addChild('level1',array('route' => 'level1', 'label' => 'Level1'));
$menu['home']['level1']->addChild('level2',array('route' => 'level2', 'label' => 'Level2'));

The Knp\Menu\MenuItem class has a getBreadcrumbsArray() method. It should return an array of items in the current active menu trail. If you are on an earlier version of KnpMenu (<= 1.1.2, my version), the returned array will be in the form of label => uri.

I guess, my breadcrumbs, when I load level2 route should look similar to:

Home -> Level1 -> Level2

because Leve1 is the parent for Level2, and Home is also its ancestor.

Instead of that, getBreadcrumbsArray() method call in my Twig template produces following data:

array(2) {
  ["Main"]=>
  NULL
  ["Home"]=>
  string(25) "/symfony/web/app_dev.php/"
}

No Level1, no Level2, only Home. What is wrong? Is it supposed to work that way? What am I doing wrong?

1
what does getCurrentUri return?Wouter J

1 Answers

0
votes

for Knp v1, should try to that to generate childrens:

$menu = $this->factory->createItem('root');
$menu->addChild['Main']
     ->seLabel['home']
$menu['Main']->addchild('level1', array('route', '@route1'))
$menu['Main']['level1']->addChild('level2', array('route', '@route2'))
{% knp_menu_get('Builder:BreadCrumb').getBreadcrumbsArray() %}