Search the Community
Showing results for tags 'sub'.
-
Hi Guys, I have the below code that I am trying to make work correctly, basically it creates a menu structure and then should only make the parent active if the page you are on belongs to that parent. at the moment the structure is wrong as it is adding too many <ul> entries for each menu. this is what it currently does: <ul id="nav"> <li class="active"><a href="admin.php">System Settings</a> <ul id="nav"> <li><a href="reports.php">Reports</a></il> </ul> <ul id="nav"> <li><a href="memblst.php?opt=createuser">Create User</a></il> </ul> </li> </ul> This is what it should be: <ul id="nav"> <li class="active"><a href="admin.php">System Settings</a> <ul> <li><a href="reports.php">Reports</a></il> <li><a href="memblst.php?opt=createuser">Create User</a></il> </ul> </li> </ul> $MENU["SYSTEMS"] = array ( 'parent'=>true, 'enabled'=>true, 'text'=>'System Settings', 'link'=> 'admin.php', 'sub_modules' => array('REPORTS','CREATE_USER') ); $MENU["REPORTS"] = array ( 'parent'=>FALSE, 'enabled'=>true, 'text'=>'Reports', 'link'=> 'reports.php', 'sub_modules' => array() ); $MENU["CREATE_USER"] = array ( 'parent'=>FALSE, 'enabled'=>true, 'text'=>'Create User', 'link'=> 'memblst.php?opt=createuser', 'sub_modules' => array() ); $MENU["MEMBER_LST"] = array ( 'parent'=>FALSE, 'enabled'=>true, 'text'=>'Member List', 'link'=> 'memberlst.php', 'sub_modules' => array() ); $MENU["SYSTEM_LOGS"] = array ( 'parent'=>FALSE, 'enabled'=>true, 'text'=>'System Logs', 'link'=> 'syslog.php', 'sub_modules' => array() ); function show_menu(&$MENU,$subIndex=false){ $menu_string = ''; $menu_string .= '<ul id="nav">'; if(!$subIndex){ foreach($MENU as $item) { if( $item['enabled']&&$item['parent'] ) { $_subString=""; if(!empty($item['sub_modules'])){ foreach($item['sub_modules'] as $sub){ $_subString .= show_menu($MENU,$sub); } } $menu_string .= '<li class="active"><a href="'.$item['link'].'">'.$item['text'].'</a>'.$_subString.'</li>'; } } }else{ if(@$MENU[$subIndex]['enabled']&&!@$MENU[$subIndex]['parent']) { $_subString=""; if(!empty($MENU[$subIndex]['sub_modules'])){ foreach($MENU[$subIndex]['sub_modules'] as $sub){ $_subString .= show_menu($MENU,$sub); } } $menu_string .= '<li><a href="'.$MENU[$subIndex]['link'].'">'.$MENU[$subIndex]['text'].'</a></il>'.$_subString; } } return $menu_string.'</ul>'; } echo show_menu($MENU);