I used the @Calle example, it worked very well ... I had to use a custom url-grabber instead of CI current_url (), since I am bypassing the index.php file with .htaccess. I also added the correct attribute tag.
Notes for beginners I broke this file in the "helpers" called "menu_helper.php" and uploaded it via the controller $ this-> load-> helper ('menu');
helpers / menu _helper.php
if ( ! function_exists('menu_anchor')) { function menu_anchor($uri = '', $title = '', $attributes = '') { $title = (string) $title; if ( ! is_array($uri)) { $site_url = ( ! preg_match('!^\w+://! i', $uri)) ? site_url($uri) : $uri; } else { $site_url = site_url($uri); } if ($title == '') { $title = $site_url; } if ($attributes != '') { $attributes = _parse_attributes($attributes); } $current_url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; $attributes .= ($site_url == $current_url) ? 'class="active"' : 'class="normal"'; return '<a href="'.$site_url.'"'.$attributes.'>'.$title.'</a>'; } }
View file:
<ul class="topnav love"> <li class="topnav-1"><?=menu_anchor(base_url()."path/to/something", "menu_item")?></li> <li class="topnav-2"><?=menu_anchor(base_url()."path/to/something", "menu_item")?></li> <li class="topnav-3"><?=menu_anchor(base_url()."path/to/something", "menu_item")?></li> <li class="topnav-4"><?=menu_anchor(base_url()."path/to/something", "menu_item")?></li> <li class="topnav-5"><?=menu_anchor(base_url()."path/to/something", "menu_item")?></li> </ul>
css:
ul.topnav li.topnav-1 a.active {something smart}
Robin morgan
source share