[eluser]Avril[/eluser]
Hi,
I have a made a library to check if a user is logged in or not (I'm learning CI :p).
Now the library is made and should work.
When I want to load the library in one of my controllers, I get the error:
Quote:Fatal error: Call to a member function is_logged_in() on a non-object in /Users/user/Sites/myBudget/application/controllers/login.php on line 10
This is my library file:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Authenticator {
/* Validate the users login credentials */
function validate(){
$this->load->model('membership_model');
$query = $this->membership_model->validate();
if($query){
$data = array(
'username' => $this->input->post('username'),
'is_logged_in' => true
);
$this->session->set_userdata($data);
return TRUE;
}else{
return FALSE;
}
}
function is_logged_in(){
$is_logged_in = $this->session->userdata('is_logged_in');
if(!isset($is_logged_in) || $is_logged_in != TRUE){
return FALSE;
}else{
return TRUE;
}
}
function logout(){
$logout = $this->session->sess_destroy();
if($logout){
return TRUE;
}
}
}
Don't worry for the query, the data will be send by passing an array to the object later on, I just copied it from my previous version where I checked the login directly in the controller.
This is my controller:
Code:
<?php
class Login extends Controller {
var $Authenticator;
function index(){
$Authenticator = $this->load->library('Authenticator');
$auth = $this->Authenticator->is_logged_in();
}
}
What am I doing wrong here?