NaGeL182 NaGeL182 - 1 year ago 151
PHP Question

Symfony2 KnpMenuBundle: set active a menu item even when its not on that menu

I created my menu builder and it works.
One of my route is


But this has a child route:


I don't want to put the view route into the menu items because without the ID it won't work.

But I want the database route to be active when the user is on the view.

How can I do this?

Answer Source

Managed to solve it with this little hack:

in the menuBuider after you add all the Children but before you return the menu i added

$request = $this->container->get('request');
        $routeName = $request->get('_route');
        switch ($routeName)
            case 'battlemamono_database_view_by_name':
            case 'battlemamono_database_view_by_id':

this checks the routes and sets the needed menu active.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download