The Session library is autoloaded
My model:
class Login_model extends CI_Model{
function __construct(){
parent::__construct();
}
public function validate(){
$username = $this->security->xss_clean($this->input->post('username'));
$password = $this->security->xss_clean($this->input->post('password'));
$this->db->where('username', $username);
$this->db->where('password', $password);
$query = $this->db->get('users');
if($query->num_rows == 1)
{
$row = $query->row();
$data = array(
'id' => $row->id,
'first_name' => $row->first_name,
'last_name' => $row->last_name,
'username' => $row->username,
'validated' => true
);
$this->session->set_userdata($data); // ### line 28 ###
return true;
}
return false;
}
}
Gives this error:
Fatal error: Call to undefined method Session::set_userdata() in /var/www/codeIgniterTest/_application/models/login_model.php on line 28
Have you loaded the Session
library?
class Login_model extends CI_Model {
function __construct()
{
parent::__construct();
$this->load->library('session');
}
Try debugging and check all the included files by.
$included_files = get_included_files();
foreach ($included_files as $filename) {
echo "$filename
";
}
I found the problem. I created my own Session class, but forgot to extend the CI_Session.
Thanks for the help!