我有3个表,其中1个用于role,menu和role_menu,我希望结果为
我已经使用以下函数成功生成了ul和li。面临如何放置角色及其下的每个菜单的问题。
public function get_menu() {
$this->db->select('ms.menu_id as id,ms.menu_name,ms.menu_title,ms.type,ms.link,ms.is_active,ms.parent as parentid,ms.icons,rm.is_active,rm.role_id');
$this->db->from('menu_settings ms');
$this->db->join('role_menus rm', 'rm.menu_id = ms.menu_id', 'INNER');
//$this->db->join('role r', 'r.role_id = rm.role_id', 'INNER');
$this->db->group_by('ms.menu_id','desc');
$query = $this->db->get();
$rResult_array = $query->result_array();
#echo $this->db->last_query();exit;
$menu = array(
'menus' => array(),
'parent_menus' => array(),
);
foreach ($rResult_array as $key => $value) {
$menu['role_id'][$rResult_array[$key]['role_id']] = $rResult_array[$key]['role_id'];
$menu['menus'][$rResult_array[$key]['id']] = $value;
$menu['parent_menus'][$rResult_array[$key]['parentid']][] = $rResult_array[$key]['id'];
}
//$this->load->model('Common');
//$all_roles = $this->Common->get_records('role', $column = '', $where = '', $start = '', $limit = '', $flag_total_count = "NO");
$side_bar_menu = $this->buildMenu1(0, $menu);
return $side_bar_menu;
}
public function buildMenu($parent, $menu) {
$html = "";
if (isset($menu['parent_menus'][$parent])) {
if ($parent <= 0)
$html .= "<ul class=''>";
else
$html .= '<ul class="">';
$countfor_active = 0;
foreach ($menu['parent_menus'][$parent] as $menu_id) {
$li_parentclass = ' ';
if (!isset($menu['parent_menus'][$menu_id])) {
$html .= "<li class='" . $li_parentclass . "'><span>" . $menu['menus'][$menu_id]['menu_name'] . "</span></li>";
}
if (isset($menu['parent_menus'][$menu_id])) {
$html .= "<li><span>" . $menu['menus'][$menu_id]['menu_name'] . "</span>";
$html .= $this->buildMenu($menu_id, $menu);
$html .= "</li>";
}
}
$html .= "</ul>";
}
return $html;
}
用户
客户