0

I'm creating a bundle with KNPMenuBundle on Symfony 2.3.x and it doesn't mark the current element, so, I thought the problem has to do with using 'uri' instead of 'route' since I'm on Symfony and all, the thing is, when I use route, the element changes from

    <li><a href="engineerings">Engineerings</a></li>

to:

        <li><span>Engineerings</span></li>

the <a> element

public function mainMenu(FactoryInterface $factory, array $options) {
        $factory = new MenuFactory();
        $menu = $factory->createItem('root');
        $menu->setChildrenAttributes(array('id' => 'tabs', 'class' => 'fl'));
        $menu->addChild('Cooperators', array('uri' => 'companies'));
        $menu->addChild('Customers', array('uri' => 'clients'));
        $menu->addChild('Engineerings', array('uri' => 'engineerings'));
        $menu->addChild('Lines', array('uri' => 'lines'));
        $menu->addChild('Priorities', array('uri' => 'priorities'));
        $menu->addChild('Projects', array('uri' => 'projects'));
        $menu->addChild('Statuses', array('uri' => 'statuses'));
        $menu->addChild('Sites', array('uri' => 'sites'));
        $menu->addChild('Reports', array('uri' => 'reports'));
        $menu->addChild('Roles', array('uri' => 'roles'));
        $menu->addChild('Users', array('uri' => 'users'));
        return $menu;
    }

the <span> element

 public function mainMenu(FactoryInterface $factory, array $options) {
        $factory = new MenuFactory();
        $menu = $factory->createItem('root');
        $menu->setChildrenAttributes(array('id' => 'tabs', 'class' => 'fl'));
        $menu->addChild('Cooperators', array('route' => 'companies'));
        $menu->addChild('Customers', array('route' => 'clients'));
        $menu->addChild('Engineerings', array('route' => 'engineerings'));
        $menu->addChild('Lines', array('route' => 'lines'));
        $menu->addChild('Priorities', array('route' => 'priorities'));
        $menu->addChild('Projects', array('route' => 'projects'));
        $menu->addChild('Statuses', array('route' => 'statuses'));
        $menu->addChild('Sites', array('route' => 'sites'));
        $menu->addChild('Reports', array('route' => 'reports'));
        $menu->addChild('Roles', array('route' => 'roles'));
        $menu->addChild('Users', array('route' => 'users'));
        return $menu;
    }

now, why does this happen? also, how can i set the current item? I can't make it display the 'current' class.

Splendonia
  • 1,329
  • 3
  • 37
  • 59

1 Answers1

2

Your problem is this line:

$factory = new MenuFactory();

You don't need it. Just remove it. This will create a new MenuFactory with it's default settings. I experience some wired behaviour myself when I create my own factory like this.

ferdynator
  • 6,245
  • 3
  • 27
  • 56
  • Most people using it with symfony have used "route" and it seems to work for them. KnpMenuBundle is not being very smart since it's not selecting the current item by itself. Thank you for answering. Also, according to what it's shown here: https://github.com/KnpLabs/KnpMenuBundle/blob/1b07578738d3425c09cfbd153276382388994f46/Resources/doc/i18n.md it does accept the "route" option – Splendonia Jan 31 '14 at 18:18
  • I am sorry. Of course you are right. There is a `route` option. I'll rewrite my answer. – ferdynator Jan 31 '14 at 18:25
  • Okay rewrote my answer. Problem was somewhere else. – ferdynator Jan 31 '14 at 18:30
  • OMG! that was it! It now shows the "current" class!!!!! and the link (Although I have to change it to "active" instead of current to make the CSS work) but OMG! Thank you VERY VERY VERY much! – Splendonia Jan 31 '14 at 18:46
  • 1
    Fixed the css class thing! Thank you again! – Splendonia Jan 31 '14 at 18:58