-
Notifications
You must be signed in to change notification settings - Fork 7.6k
DynamicMenu
World Wide Web Server edited this page Jul 4, 2012
·
24 revisions
Menu library. Will show/hide sub-menus depending on in which, uri->segment the user is browsing. Just add it in to autoload.
I call it from the view file like this: [code] $menu = $this->menu->mkmenu(); [/code] Where ever in the view file you like to have your menu you would enter this: [i]Make sure you also load the html helper for ul[/i] [code] <?=ul($menu,array('class' => 'menu','id' => 'menu'));?> [/code]
[code] class Menu { function Menu() { log_message('debug', 'Menu: initialized'); } function mkMenu() { $CI =& get_instance();
$menu = array(
anchor('account', 'Account'),
anchor('news', 'News'),
anchor('ticket', 'Support')
);
$sub['account'] = array(
anchor('account/secquestion','Security'),
anchor('account/password','Password'),
anchor('account/user','Profile')
);
$sub['news'] = array(anchor('news/post','Post'));
$segment = $CI->uri->segment(1);
foreach($menu as $k => $v){
$menutmp[$k] = $v;
if (strripos($v, $segment) !== FALSE){
$menu[$menu[$k]] = $sub[$segment];
unset($menutmp[$k]);
$menutmp[$menu[$k]] = $sub[$segment];
}
}
return $menutmp;
}
} [/code]