Thanks to this extensions you'll be able to easily have ajax links inside your menus.
Tested on Yii version 1.1.7 It should work on every release of Yii starting from 1.1.5
It's extremely easy:
put the extension inside the extension folder and then just create your menus.
$this->widget('ext.AjaxMenu',array( 'items'=>array( array('label'=>'Home', 'url'=>array('/site'), 'linkOptions' => array('id' => 'idname'), 'ajax' => false), array('label'=>'About', 'url'=>array('/site/page', 'view'=>'about'), 'ajax' => array('update' => '#content')), array('label'=>'Contact', 'url'=>array('/site/contact')), array('label'=>'Login', 'url'=>array('/site/login'), 'visible'=>Yii::app()->user->isGuest), array('label'=>'Logout ('.Yii::app()->user->name.')', 'url'=>array('/site/logout'), 'visible'=>!Yii::app()->user->isGuest) ), 'optionalIndex'=>true, 'ajax'=>array( 'update' => '#page', ), 'randomID'=>true, ));
with this extensions you have two new options:
optionalIndex is a boolean. If you set it on true and you'll write your controller name as the url value without specifying the index action, the menu item will be highlighted as if you did.
ajax this is just like the ajaxOptions attribute of the ajaxLink element.
Therefore it supports update, replace and success.
If you use that parameter every single link inside your menu will be created with that value, if you won't say otherwise.
randomID this parameter is a boolean and defaults to false. If you set it on true random strings will be generated at the end of the id to avoid multiple ajax request
For that reason your menu items have a new property too, and it's named ajax as well.
If you set it on false that menu item will be a regular link, even if you setted the ajax property of the menu.
If you want to override the behavior setted by the ajax property you can use the item ajax parameter to set the behavior you want.
If you just need a single link to be an ajax link you can forget about the menu ajax property and just set that single item ajax property.
you can use both "update" and "replace" ajax options without having to worry about what's going to happen to the item active status. This widget will automatically generate the needed code to update the active status of your menu items.
If you choose to use a different CSS class for you active items you won't have to worry about anything, because the widget will use the classname you chose.
if you don't know how to use ajaxLink look at the official documentation
added the corrections made by anupam_sam
added randomID property
now when you click on an ajax link the active status on the menu will be updated.
from now on the random ids will start with letters to avoid weird problems on certain browsers (thanks mjkulet)