Welcome Guest, Not a member yet? Register   Sign In
Loading Controllers
#2

[eluser]JoostV[/eluser]
I normally write an authentication library for this, that checks whether a user is logged in. If he is not, the library redirects him to the login page. I call the check_logged_in() function in every controller that needs to be behind login.

The reason I place this logic in a library is that this way I can use it anywhere I like and if I whish to change the procedure I only have to do this once, in the library.

Example controller
Code:
$this->load->library('auth');
function __construct() {
    // Retrieve logged in user data. If visitor is not logged in they are redirected to login page
    $this->data['user'] = $this->auth->check_logged_in();
}

You can extend this further by passing a role that a logged in user must have to access a certain controller or method.
Code:
$this->data['user'] = $this->auth->check_logged_in('administrator');


Messages In This Thread
Loading Controllers - by El Forum - 05-28-2009, 12:36 PM
Loading Controllers - by El Forum - 05-28-2009, 01:47 PM
Loading Controllers - by El Forum - 05-28-2009, 02:47 PM
Loading Controllers - by El Forum - 05-28-2009, 03:12 PM
Loading Controllers - by El Forum - 05-28-2009, 03:38 PM
Loading Controllers - by El Forum - 05-28-2009, 06:24 PM



Theme © iAndrew 2016 - Forum software by © MyBB