0

Hi all i'm searching for a usage of IonAuth library for Codeigniter 2.x and i'm curious to learn how it works.

Downloading the package i have a controller auth.php. i had a look at this http://blog.nexico.net/article/secure-area-codeigniter-framework-and-ion-auth

So i create, in the core folder of CI, a MY_Controller. But how can i use it?

1 Answer 1

2

Working with ion_auth.php library is pretty easy. You need to follow these steps. I assume you have followed ion_auth installation process.

First you need to create a MY_Controller class and put it in core

Class MY_Controller Extends CI_Controller{
    public function __construct(){
        parent::__construct();
        if (!$this->ion_auth->logged_in()) 
        {
            redirect(site_url('auth/login'));
        }
    }
}

Make sure you autoload the ion_auth library. The second important thing is that you need to extend your every controller with MY_Controller.
(Note : if you dont want to extend with MY_Controller but want to use simple controllers that extend CI_Controller put the above condition in every controller's constructor) If user is not logged in and try to access any page he will be redirected to auth/login.

Another useful function is here.

$user   =    $this->ion_auth->user()->row();

This will return the logged in user information.

Hope that's all you need.

1
  • @ocrama you should accept the answer by checking on check sign Sep 27, 2013 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.