KnpMenuBundle: why using 'route' instead of 'uri' transforms the <a> element to <span>?

1k Views Asked by At

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.

1

There are 1 best solutions below

5
On BEST ANSWER

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.