[eluser]adamp1[/eluser]
What you want is to create a basic auth library. Now a library is a collection of functions which perform actions. For example log a user in.
You then need a controller to show the login form to the user.
So a basic layout of the auth library would be as follows (Userlib.php):
Code:
class Userlib {
function Userlib()
{
// Constructor function
}
// Checks a user is logged in
function check()
{
// Check if a user is logged in
// If not send them to the login form
redirect('auth/login','location');
}
// Perform the login, i.e. check the users data is valid
// If not redirect back to the login form
function login()
{
// Perform login
}
}
Then you would have an auth controller (auth.php):
Code:
class Auth extends Controller {
function Auth()
{
$this->load->library('userlib');
}
function login()
{
// Show login form
}
}
Then to make sure the user is logged in when accessing the blog/welcome controller you would do the following:
Code:
class Blog extends Controller {
function Blog()
{
$this->load->library('userlib');
// Check the user is logged in
$this->userlib->check();
}
function index()
{
// Blog code goes here
}
}
I hope my example is right and can help a little. The reason this method should work is your seperating the code to perform the different tasks out.
So all the code to check a user is logged in, to log the user in is in the Userlib library.
Then when you want to make sure a user is logged in, load the library and call the check method. If they are logged in, nothing will happen and the controller will load. If they aren't logged in then they will be sent to the login form.