I use knpmenubundle for my site, and here is my problem: I have a list of users listed along this route: / admin / users and the menu looks like this:
User (is opened) list (is active) add new
in the list view, the list element in the menu is active, as I want in adding a new view, the add new element in the menu is active, as I want
but when I want to edit a user that still exists, I cannot activate the Users element because the route has a dynamic parameter
this is how my site is structured:
in src / dn / AdminBundle / Resources / Config / routing.yml
# Users
in application / ressources / view / layout / html / twig
{{ render(controller("dnAdminBundle:Common:leftMenu")) }}
in src / dn / AdminBundle / Controller / CommonController
public function leftMenuAction() { return $this->render('dnAdminBundle:Common:leftMenu.html.twig'); }
in src / dn / AdminBundle / Resources / view / Common / leftMenu / html.twig
{{ knp_menu_render('leftMenu', {'template':'dnAdminBundle:Menu:knp_menu.html.twig', 'currentClass':'active', 'ancestorClass':'active'}) }}
in src / dn / AdminBundle / Resources / config / services.yml
services: dn_admin.menu_builder: class: dn\AdminBundle\Menu\MenuBuilder arguments: ["@knp_menu.factory"] dn_admin.menu.leftMenu: class: Knp\Menu\MenuItem factory_service: dn_admin.menu_builder factory_method: createLeftMenu arguments: ["@request"] scope: request tags: - { name: knp_menu.menu, alias: leftMenu }
in src / dn / AdminBundle / Menu / MenuBuilder.php namespace dn \ AdminBundle \ Menu;
use Knp \ Menu \ FactoryInterface; use Symfony \ Component \ HttpFoundation \ Request; class MenuBuilder {private $ factory;
/** * @param FactoryInterface $factory */ public function __construct(FactoryInterface $factory) { $this->factory = $factory; } public function createLeftMenu(Request $request) { // root $menu = $this->factory->createItem('root'); $menu->setChildrenAttributes(array('class' => 'sidebar-menu')); // Users $l = $menu->addChild('Users', array( 'uri' => '#', )); $l->setAttribute('class', 'treeview'); $l->setChildrenAttribute('class', 'treeview-menu'); $l->addChild('Liste', array( 'route' => 'dnAdmin_userList', )); $l->addChild('Edit', array( 'route' => 'dnAdmin_userEdit', 'routeParameters' => $request->get('id'), )) ->setDisplay(false); }
but $ request-> get ('id') returns an empty string
Does anyone have an idea on how I can get the current parameter in knpmenubundle?
thanks