I am trying to integrate the following code into my project. it is held in a library
function do_std_login($email, $password) {
$CI =& get_instance();
$login = $CI->users_model->login($email, md5($password));
if($login){
$session_array = array(
'user_id' => $login->user_id,
'name' => $login->name,
'type' => 'Standard'
);
$CI->session->set_userdata($session_array);
// Update last login time
$CI->users_model->update_user(array('last_login' => date('Y-m-d H:i:s', time())), $login->user_id);
return true;
} else {
$this->errors[] = 'Wrong email address/password combination';
return false;
}
}
I am calling it this way:
$login = $this->jaclogin->do_std_login($this->input->post('email'),$this->input->post('password'));
but when I run it I get the following error
A PHP Error was encountered Severity: Notice Message: Undefined property: Login::$users_model Filename: libraries/jaclogin.php Line Number: 45
I have check I am do load the correct library in the codeigniter autoload file.
Any Ideas?
Thanks
Jamie Norman
$config['log_path'] = 'another/directory/logs/'; CI will then create the log file in the directory. monitor the log files as you like. You can get the debug message to see if your model is already loaded or not in the log files.
All of the available libraries are located in your system/libraries/ directory. In most cases, to use one of these classes involves initializing it within a controller using the following initialization method: $this->load->library('class_name');
CodeIgniter has rich set of libraries, which you can find in system/libraries folder but CodeIgniter is not just limited to system libraries, you can create your own libraries too, which can be stored in application/libraries folder. You can create libraries in three ways.
Using your CI instance, load your model explicitly in the library like so..
function do_std_login($email, $password) {
$CI =& get_instance();
//--------------
$CI->load->model('users_model'); //<-------Load the Model first
//--------------
$login = $CI->users_model->login($email, md5($password));
if($login){
$session_array = array(
'user_id' => $login->user_id,
'name' => $login->name,
'type' => 'Standard'
);
$CI->session->set_userdata($session_array);
// Update last login time
$CI->users_model->update_user(array('last_login' => date('Y-m-d H:i:s', time())), $login->user_id);
return true;
} else {
$this->errors[] = 'Wrong email address/password combination';
return false;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With