KnpLabs/KnpMenuBundle — Issue #90: Setting current item for dynamic pages
Author: HMUDesign
Created: 2011-12-08 22:16:33+00:00
State: open

This is a fairly general setup, but I will explain it with my current specific example. I am creating a real estate web site and there is a section for Agents. The link to the agents page (/agents) is in the menu, but the agents themselves (which are pulled from a database) are not. When visiting /agents the correct item is current, but when visit /agents/debi, the /agents link is not current but I would like it to be. Is there already a way to enable this kind of functionality, besides a mess of if's, sub_str's, etc in the menu factory?

If not, it seems the easiest way to implement this kind of behavior would be to enable certain menu items to match to the beginning of the URI, rather than the whole thing. IE: /agents would match /agents/debi as well as /agents.

A usable alternative would be a way to set the current URI in the controller (probably via a service), which would be done in the special exception that I am on one of these special pages.

If you feel it would be a worthwhile to implement one of these options, I would be happy to create a PR, but I am not sure where to start.