简体   繁体   中英

How to create permisison based on user group in codeigniter?

I am using codeigniter ion authentication for user group maintenance

Here's link for ion authenticaiton documentation

In Edit user group i would like to add menus to access for particular group alone. how to design a mysql table and access it in our controller and view page to restrict page based on user group. Please check with the below image 在此处输入图片说明

I have created menu table and menu permission table seperately.

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

Check whether the current logged in user group id is available in menu permission table or not

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM