Skip to content
World Wide Web Server edited this page Jul 4, 2012 · 24 revisions

Category:Help::TipsAndTricks

Menu library. Will show/hide sub-menus depending on in which, uri->segment the user is browsing. Just add it in to autoload.

[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]

Clone this wiki locally