Button Menu Kit Current Symfony 2 Element

I have a question regarding the rendering of the KnpMenu package for Symfony2. From what I read, there should be a “current” class in the corresponding route element. I read the Knp documentation and they say something about RouteVoter, but I can't get it to work. Any ideas?

Builder Code:

<?php // src/Acme/DemoBundle/Menu/Builder.php namespace Acme\DemoBundle\Menu; use Knp\Menu\FactoryInterface; use Symfony\Component\DependencyInjection\ContainerAware; class Builder extends ContainerAware { public function mainMenu(FactoryInterface $factory, array $options) { $menu = $factory->createItem('root'); $menu->addChild('Home', array('route' => 'index')); $menu->addChild('About Me', array('route' => 'products')); return $menu; } } 
+8
php symfony menu knpmenubundle
source share
2 answers

Well, it looks like this solution seems to work: https://github.com/KnpLabs/KnpMenuBundle/issues/122#issuecomment-6563863

+4
source share

After 10 months, I implemented the solution described above, but found that it was confused. I am using the following method.

 class Builder extends ContainerAware { public function mainMenu(FactoryInterface $factory, array $options) { $menu = $factory->createItem('root'); // Manually set the current URI. $menu->setCurrentUri($this->container->get('request')->getRequestUri()); // ... } } 

I turned a blind eye to semantics, but what happened to an approach similar to the code sample above? Please provide feedback as needed.

+4
source share

All Articles