hameed hameed - 1 year ago 95
PHP Question

How to set menu items as active in Yii framework?

I'm new to Yii framework..
Now i working with yii1.1.6 version.In admin panel menus i want to display as active menu while which menu item is selected.Please help me how to make menu item as active...

<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav side-nav">
<li class="">
<a href="<?php echo Yii::app()->createUrl('site/index'); ?>"><i class="fa fa-fw fa-dashboard"></i> Home</a>
</li>

<li class="">
<a href="<?php echo Yii::app()->createUrl('site/page',array('site/page', 'view'=>'about')); ?>"><i class="fa fa-fw fa-bar-chart-o"></i> About Us</a>
</li>

<li class="">
<a href="<?php echo Yii::app()->createUrl('site/contact'); ?>"><i class="fa fa-fw fa-table"></i> Contact Us</a>
</li>

</ul>

</div>

Answer Source

You can compare your controller id and action id like this:

if(Yii::app()->controller->id == 'site' && Yii::app()->controller->action->id == 'index'){
    echo '<li class="active">';
} 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download