0

How do you implement in codeigniter access control? or exempt certain functions to be executed in your controller? I am using ion_auth for my authentication system.

I use MY_Controller to check whether the user is logged in: where:

class MY_Controller extends CI_Controller {

public function __construct()
{
        parent::__construct();

        if(!$this->ion_auth->logged_in())
        {
           redirect('auth/login', 'refresh');
        }
    }

In my suggestion controller:

class Suggestion extends MY_Controller {

    public function __construct()
    {
        parent::__construct();
        $this->load->model('Suggestion_model', 'suggestion');
    }

    public function create()
    {
        //some codes
    }

    public function settings()
    {
        //some codes
    }
}

Now my question is, how do I restrict each function to be accessed?

Let's say if you are a guest you are able to access

index.php/suggestion/create 

and if you are admin, then you can access below controller

index.php/suggestion/settings.

but if not then you cannot access, please point me in the right direction. thank you.

mmr
  • 516
  • 11
  • 30

0 Answers0