Glänzende Perlen Glänzende Perlen - 5 months ago 12x
PHP Question

CodeIgniter Ion Auth: How is is_admin() working?

I'm using the Ion_auth for CodeIgniter in my project auth library. I'm trying to make a similar function as

for other user types (there are three user types other than the admin) to check whether the logging in user is of one of those three types so I can redirect them to their respective pages. Ion_auth is using an event called is_admin but I can't understand where this is happening in the
and how it checks whether the logged in user is admin. So how can I make other functions/events similar to this one?

I know I can just do something like query the database and check the user group but I want to do the way Ion_auth has done. That way I can also satisfy myself by actually understanding the stock code.


I am just looking at source code on github.

As lots of auth libraries store, information you are looking for in session and library itself checks session variables.

your function you are looking for is on line 447 in file application/libraries/Ion_auth.php

public function is_admin($id=false)

        $admin_group = $this->config->item('admin_group', 'ion_auth');

        return $this->in_group($admin_group, $id);

In order to create your own I suggest you to reverse engeneer model (ion_auth_model.php)

But! Ion already has a workaround for you, this method is what you are looking for


$group = 'gangstas';
    if (!$this->ion_auth->in_group($group))
        $this->session->set_flashdata('message', 'You must be a gangsta to view this page');