codeigniter中的动态菜单和角色权限

Hello Guyzz i am new in codeigniter, and i need help in role base login in system, i have two table 1st in Category and 2nd is user_reg,

In 2nd table category_id stored like this 1,2,3 so is it Possible to fetch this id?

Please Give me suggestion and solution i am new in CI, give me some guidance about dynamic menu and role based login access

Category:enter image description here

User: enter image description here

database tables example :

CREATE TABLE IF NOT EXISTS `users` (
  `user_id` int(11) NOT NULL AUTO_INCREMENT,
  `first_name` varchar(100) NOT NULL,
  `last_name` varchar(100) NOT NULL,
  `username` varchar(100) NOT NULL,
  `password` text NOT NULL,
  `create_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`user_id`),
  KEY `user_id` (`user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;

INSERT INTO `users` (`user_id`, `first_name`, `last_name`, `username`, `password`, `create_at`) VALUES
(1, 'ali', 'qorbani', 'aliqorbani', '63bed66f3d9dcd13440490d90738f816', '2018-07-28 08:34:01'),
(2, 'mohammad', 'ahmadi', 'mohammad', '316946a88ad51d75465c4c0b1e4a066a', '2018-07-28 08:34:01');


CREATE TABLE IF NOT EXISTS `user_groups` (
  `group_id` int(11) NOT NULL AUTO_INCREMENT,
  `group_name` varchar(100) NOT NULL,
  `create_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`group_id`),
  KEY `group_id` (`group_id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;

INSERT INTO `user_groups` (`group_id`, `group_name`, `create_at`) VALUES
(1, 'superadmin', '2018-07-28 08:35:56'),
(2, 'admin', '2018-07-28 08:35:56'),
(3, 'moderator', '2018-07-28 08:36:12'),
(4, 'customer', '2018-07-28 08:36:12');

CREATE TABLE IF NOT EXISTS `user_roles` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `group_id` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `id` (`id`),
  KEY `user_id` (`user_id`),
  KEY `group_id` (`group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

ALTER TABLE `user_roles`
  ADD CONSTRAINT `user_roles_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `user_roles_ibfk_2` FOREIGN KEY (`group_id`) REFERENCES `user_groups` (`group_id`) ON DELETE CASCADE ON UPDATE CASCADE;
COMMIT;

codes for your model will be like this.

//User_model

public function add($data){
    $this->db->insert('users',$data);
    return true;
}
public function update($data,$id){
    $this->db->where('user_id',$id);
    $this->db->update('users',$data);
    return true;
}

public function add_user_roles($user_id,$roles = array()){
    $this->db->where('user_id',$user_id);
    $this->db->delete('user_roles');
    foreach ($roles as $role){
        $this->db->insert('user_roles',['user_id'=>$user_id,'group_id'=>$role]);
    }
    return true;
}

and the example for your controller Edit method will be like this snippet:

//Users controller
public function edit($user_id){
    if($this->form_validation->run() == FALSE) {
        $data_view['user'] = $this->User_model->get_user($user_id);
        $this->load->view('user_edit',$data_view);
    }else{
    $first_name = $this->input->post('first_name');
    $last_name = $this->input->post('last_name');
    $username = $this->input->post('username');
    $password = md5($this->input->post('password'));
    $user_roles = $this->input->post('roles');
    $data_user_update = array(
        'first_name'    =>  $first_name, 
        'last_name'     =>  $last_name, 
        'username'      =>  $username, 
        'password'      =>  $password
    );
    $this->User_model->add_user_roles$user_id,$user_roles);
    $this->User_model->update($data_user_update,$user_id);
    $this->session->set_flashdata('success','user updated correctly');
    redirect('users/edit/'.$user_id);
    }
}

Never ever use this way anymore! create 2 different tables (users,user_groups). add a column to user table group_id and then use join function to get theme for more information see this link

if you can't figure out please post your table data here and i'll help you :-)

here is my (post,post_tax,post_tax_relation) tables screenshot. i think it can help you wat you need. remember on create,update users you must update relation table (I mean delete all relation refer to that user and create new ones on every update). Posts table - (use it as your user table)

taxonomies - use it as your **User Groups**

relations - for collect all user permission levels