-
-
Save guiyomh/763151ac7ac5412cb14856fbb11f01d9 to your computer and use it in GitHub Desktop.
Symfony 2 breadcrumbs based on KnpMenuBundle (KnpMenu 2.1)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{ knp_menu_render('main', {'template': ':Menu:breadcrumb.html.twig'}) }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace AppBundle\Menu; | |
use Knp\Menu\FactoryInterface; | |
class Builder | |
{ | |
/** | |
* @var FactoryInterface | |
*/ | |
private $factory; | |
/** | |
* @param FactoryInterface $factory | |
*/ | |
public function __construct(FactoryInterface $factory) | |
{ | |
$this->factory = $factory; | |
} | |
/** | |
* @param array $options | |
* | |
* @return \Knp\Menu\ItemInterface | |
*/ | |
public function createMainMenu(array $options) | |
{ | |
$menu = $this->factory->createItem('Dashboard', ['route' => 'dashboard']); | |
$menu->addChild('Foo', ['route' => 'foo_list']); | |
$menu['Foo']->addChild('Create Foo', ['route' => 'foo_create', 'display' => false]); | |
$menu->addChild('Bar', ['route' => 'bar_list']); | |
$menu['Bar']->addChild('Create Bar', ['route' => 'bar_create', 'display' => false]); | |
return $menu; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
app.menu.builder: | |
class: AppBundle\Menu\Builder | |
arguments: | |
- '@knp_menu.factory' | |
tags: | |
- { name: knp_menu.menu_builder, method: createMainMenu, alias: main } | |
app.twig.menu_extension: | |
class: AppBundle\Twig\MenuExtension | |
arguments: | |
- '@knp_menu.helper' | |
- '@knp_menu.matcher' | |
tags: | |
- { name: twig.extension } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment