Manage or Highlight Active link or page in Codeigniter?

I always use this CodeIgniter Helper for all of my CI projects to Highlight Current or active link in the menu bar.

How it works

The active_link() function simply accept the name of a controller as a parameter and it will check if the current controller is equal to the the given string, if it is equal it will return the active string, otherwise empty string. To get an active controller this function is using CI’s router class’s fetch_class() method. i.e.$CI->router->fetch_class();

CI Nav Helper

Create a file in applications/helper directory with nav_helper.php name.copy and paste the code you find below

How to load:

To use this Helper function, you have to load it. you can load it with two methods, one is controller level/method level and another one is global level.

open the application/config/autoload.php

How to use it

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

0 0 vote
Article Rating
Subscribe
Notify of
guest
4 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
lonesomedreams
lonesomedreams
6 years ago

Very simple and no hassle. Thank you very much! It worked for me. Cheers.

Ben
Ben
5 years ago

This is almost magical 😉 thanks so much for thinking of this and sharing it.

eranda weligala
eranda weligala
4 years ago

cant works

Ajay Babu
Ajay Babu
2 years ago

Thanks man, its working in main menu level. For example I have 4 submenu under my main menu ( in admin side bar). Then when I click on the 2nd level sub menu then my main menu and this 2nd sub-menu should be in active. How can I achieve this? I mean this is working on controller level but what about function level? is there any suggestion?

DMCA.com Protection Status
4
0
Would love your thoughts, please comment.x
()
x