xiidea / ezRbac

A simple yet easy to implement Role Based Access Control Library for popular PHP framework Codeigniter
http://xiidea.github.io/ezRbac/
86 stars 39 forks source link

Access to method other than index blocked #24

Closed rebirthtobi closed 7 years ago

rebirthtobi commented 7 years ago

After defining my access_map in the controller, using the code

class Branch extends CI_Controller{
    function __construct(){
        parent::__construct();
        $this->load->model(['Branch_model', 'Action_branch_model']);
        $this->load->library('form_validation');        
    $this->load->library('datatables');
    }

    public function access_map(){
        return array(
            'index'=>'view',
            'update'=>'edit',
            'update_action'=>'edit',
            'delete'=>'delete',
            'excel' => 'excel',
            'create' => 'publish',
            'create_action' => 'publish',
        );
    }

it only allows me to access the index and block out all other methods and also how can i add more roles

rebirthtobi commented 7 years ago

i just fix it now but it might help anybody, it appears that the controller saved in the database starts with a Capital letter and but the User_access_map.php quries in small letter. i change the User_access_map.php to this below for it to work

function set_permission($controller,$role,$permission){
        $data['user_role_id']=$role;
        $data['controller']=strtolower($controller);
        $data['permission']=$permission;
        $where=array('user_role_id'=>$role,'controller'=>$controller);
        $query = $this->db->get_where($this->_table_name, $where, 1, 0);
        if ($query->num_rows() == 0) { //Insert
            $this->db->insert($this->_table_name, $data);
            return;
        }
        //Existing data so update
        $this->db->update($this->_table_name, $data,$where);
    }

i have to add strtolower for it to work but i still need to know how more roles apart from the database

ronisaha commented 7 years ago

You can add more role in db. If you are referring to view, edit .. you can add in default_access_map config

rebirthtobi commented 7 years ago

Thanks