Cmenu's Isitemactive With Respecting Get Parameters

Hi all,

Comment in CMenu.php’s line 304 says: “Note that the GET parameters not specified in the ‘url’ option will be ignored”. Is there an easy workaround for this?

I have a menu, where I have options for showing items by type and showing all items. It looks like this:


Array

(

	[0] => Array

	(

		[label] => Show videos

		[url] => Array

		(

			[0] => /content/manage/index

			[type] => 1

		)

	)

	[1] => Array

	(

		[label] => Show audios

		[url] => Array

		(

			[0] => /content/manage/index

			[type] => 2

		)

	)

	[2] => Array

	(

		[label] => Show texts

		[url] => Array

		(

			[0] => /content/manage/index

			[type] => 3

		)

	)

	[3] => Array

	(

		[label] => Show all

		[url] => Array

		(

			[0] => /content/manage/index

		)

	)

)

As you can see, first three items has extra GET parameter specified, while last one doesn’t have it.

Current CMenu’s implementation ignores that and whenever I select any of first three items, my menu contains two active (highlighted) items – currently selected and the last one (as in case of last one, current route’s GET parameters part is ignored, so it matches as well).

The only solution I found up until now, is to add extra GET parameter to last option, for example [type] => 3 or [type] => ‘all’ and ignore it in the Controller. But this isn’t an option in my current project.

Does anyone has any other idea, how to workaround this problem?

[size=2]can you please post the array code?[/size]

Sorry, it is impossible. There is no permanent menu (array) structure. My entire menu is generated on-the-fly with data taken from database (models).

What I’ve posted in initial question is an effect of calling print_r($items), but I can’t post $items itself, as it is being generated entirely, through many functions.

I don’t think, that problem lies in my own code. As I wrote, it is most likely Yii problem and framework code does, what is exactly written in the comments, i.e. CMenu::isItemActive ignores Yii::app()->controller->getActionParams() part and does compare (whether item is active or not) basing only on Yii::app()->controller->getRoute(). Which seems to be wrong, as – in my case – two separate menu items fullfils this check and returns true.

I don’t see even a bit of “active” in your code, so I don’t understand, how can this example be related to discussed problem? Can you provide some details how can I / should I use your code to fix problem described in my question?

BTW: Issue reported on GitHub, but it is currently closed as wont-fix.