Question

I am building a website and am new to Codeigniter and Ion Auth. My website consists of three tiers of user: regular user, moderator and admin. I understand is_admin and is_logged in, but can't figure out how to create a new group for my moderators.

Ideally, I would like to use something like this to protect my moderator pages:

if (!$this->ion_auth->in_group('moderator'))
{
    //redirect them to the home page because they must be an administrator to view this
    redirect($this->config->item('base_url'), 'refresh');
}

How can I create a new group of user for my moderators? Is it something I need to do in my database? I've seen code in the documentation but am not sure where/how to use it.

Was it helpful?

Solution

You can either manually add the group to the groups table of your db - I guess this is easiest for you as you probably only need to do it once - or you could use the method create_group() built into the library:

 $this->ion_auth->create_group('moderator', 'This is the moderators group');

Then you will be able to check your users as you suggest.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top