Yii Framework Forum: Cmenu's Isitemactive With Respecting Get Parameters - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Cmenu's Isitemactive With Respecting Get Parameters Rate Topic: -----

#1 User is offline   Trejder 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,193
  • Joined: 06-October 10
  • Location:Southern Poland

Posted 20 September 2013 - 03:43 AM

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?

Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!
0

#2 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 866
  • Joined: 19-February 13
  • Location:India

Posted 20 September 2013 - 04:40 AM

can you please post the array code?
Thanks,
Ankit Modi
Skype : amodi06
0

#3 User is offline   Trejder 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,193
  • Joined: 06-October 10
  • Location:Southern Poland

Posted 20 September 2013 - 07:21 AM

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.
Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!
0

#4 User is offline   Trejder 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,193
  • Joined: 06-October 10
  • Location:Southern Poland

Posted 20 September 2013 - 12:39 PM

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.
Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users