CMenu item active for several URLs

Hi all,

I have the following problem in my app.

A user wants to buy something. In the navigation he clicks on Buy, which links to user/buy (navigation item Buy active). Because he hasn’t provided all user details yet, he gets redirected to user/update (navigation item Buy no longer active). Then, because he buys for the first time and he hasn’t entered a company yet, he gets redirected to company/create (navigation item Buy no longer active). Finally he comes back to user/buy to actually buy (navigation item Buy active).

The way the CSS active class gets set is based on the data model. However, for a user friendly site, you want to think in terms of user workflows and I want to have the Buy navigation item active for this whole process.

How can I accomplish this keeping in mind that for example being on user/update doesn’t necessarily have to be a redirect from user/buy. In other words, being on user/update shouldn’t automatically make the Buy navigation active. It’s context specific, depending on where the user came from. So I guess I’d have to add a parameter “referrer” to the URL.

Because I’m a complete beginner when it comes to OOP and Yii, user ciss provided me with some code in the chat. I couldn’t get it work and it would be great if someone could give me a hand with very clear instructions in layman’s terms.

Thanks a lot…




class MultiActiveMenu extends CMenu {

protected function isItemActive($item,$route)


	$urls = array_merge(array($item['url']), !empty($item['activeUrls']) ? $item['activeUrls'] : array());

	foreach($urls as $url)


		if(is_array($url) && !strcasecmp(trim($url[0],'/'),$route))




				foreach(array_splice($url,1) as $name=>$value)


					if(!isset($_GET[$name]) || $_GET[$name]!=$value)

						return false;



			return true;




	return false;






array('label'=>'Buy', 'url' => array('/user/buyChooseBuyer'), 'activeUrls' => array(array('/company/create', array('referrer'=>'buy'))), 'visible'=>!Yii::app()->user->isGuest),

Are you running


or :


It should be the later.

Other than that the code you posted looks like it should work. Does removing the array(‘referrer’ =>‘buy’) part at least make the menu activate in company/create?


Thanks for your reply. As a beginner I have to ask, where exactly should I put the code below?