Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set class="active" to navigation menu in codeigniter?

I just start up to be a web developer. Now I create a dynamic website for the first time. I don't know how to set class="active" to the navigation menu. Here is my menu code:

<li>
    <a href="<?php echo base_url(); ?>patient/createpatient"><i class="fa fa-users fa-lg"></i> Create Patient </a>
</li>
<?php } ?>
    <li>
       <a href="<?php echo base_url(); ?>patient/listpatient"><i class="glyphicon glyphicon-list-alt fa-lg"> </i> List Patients </a> 
    </li>
<?php if( $usertype == "Admin"){?>
    <li>
    <a href="<?php echo base_url(); ?>user/"><i class="fa fa-list fa-lg"> </i> List Users </a> 
    </li>`
like image 880
Phearum Chheang Avatar asked May 21 '15 07:05

Phearum Chheang


1 Answers

You can use $this->uri->segment();

<li>
    <a href="<?php echo base_url(); ?>patient/createpatient" <?php if($this->uri->segment(1)=="menu_name"){echo 'class="active"';}?> ><i class="fa fa-users fa-lg"></i> Create Patient </a>
</li>
<?php } ?>
    <li>
       <a href="<?php echo base_url(); ?>patient/listpatient" <?php if($this->uri->segment(1)=="menu_name"){echo 'class="active"';}?> ><i class="glyphicon glyphicon-list-alt fa-lg"> </i> List Patients </a> 
    </li>
<?php if( $usertype == "Admin"){?>
    <li>
    <a href="<?php echo base_url(); ?>user/" <?php if($this->uri->segment(1)=="menu_name"){echo 'class="active"';}?> ><i class="fa fa-list fa-lg"> </i> List Users </a> 
    </li>
like image 200
Nick Berardi Avatar answered Sep 28 '22 08:09

Nick Berardi