2015-05-14 63 views

回答

1

我已經創建菜單表和菜單權限表分開。

menu table 
    menu id 
    menu name 
menu permission table 
id 
menuid 
usergroup_id 

檢查登錄的用戶組ID當前是否在菜單權限表用或不

public function get_menus($user_group_id) { 
    if ($user_group_id == 1) { 
     $query = $this->db->query("SELECT * FROM menus where parent_id=0"); 
     $get_results = $query->result(); 
    } else { 
     $query = $this->db->query("SELECT * FROM menu_permissions where user_group_id = $user_group_id"); 
     $get_results = $query->result(); 
     $user_perm = array(); 
     foreach($get_results as $key=> $get_perm){ 
      // echo $get_results[$key]->menu_id; 
      ////print '<pre>'; 
      $user_perm[] = $get_results[$key]->menu_id; 
     } 
     $user_perm = implode(', ', $user_perm); 
     $query = $this->db->query("SELECT * FROM menus WHERE id IN (".$user_perm.")"); 
     $get_results = $query->result(); 
    } 
    //print_r($get_results); 
    /*$user_perm = array(); 
    foreach($get_results as $key=> $get_perm){ 
     // echo $get_results[$key]->menu_id; 
     ////print '<pre>'; 

     $user_perm[] = $get_results[$key]->menu_id; 
    }*/ 
    return $get_results; 
} 
相關問題