This is how I do it, change to suit your needs.
PHP Code:
// Controller
/**
* index ()
* -------------------------------------------------------------------
* Check to see if the Admin is logged in.
* Else show the login view.
*/
public function index()
{
// if the user is logged in.
if (logged_in())
{
$this->auth->view('dashboard');
}
// show the login view.
else
{
$this->auth->login();
}
}
------------------------------------
// Auth Library
// -------------------------------------------------------------------
/**
* logged_in ()
* -------------------------------------------------------------------
*
* Check to see if a user is logged in
*
* Look in the session and return the 'logged_in' part
*
* @return bool
*/
public function logged_in()
{
if ($this->CI->session->userdata('logged_in') === true)
{
return true;
}
else
{
return false;
}
}
-----------------------------------------------------
// Helper
// -----------------------------------------------------------------------
/**
* logged_in
*/
if ( ! function_exists('logged_in'))
{
/**
* logged_in ()
* -------------------------------------------------------------------
*
* @return bool
*/
function logged_in()
{
$CI =& get_instance();
if ($CI->auth->logged_in() == TRUE)
{
return TRUE;
}
return FALSE;
}
}
With the auth_helper it makes it easy for me to use methods in the views for
checking users etc;
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )