Sunday, May 20, 2018

php - CodeIgniter - Call to a member function model() on a non-object




I have a login form that is being created in the view. Then in my controller I'm trying to load my model but it doesn't seem to load. Looked up a few answer here on stackoverflow and almost everybody says autoload model, import the database library,etc. I did that but I'm still getting the error




    Fatal error: Call to a member function model() on a non-object in C:\xampp\htdocs\\project\application\controllers\login.php on line 11 

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Login::$load

Filename: controllers/login.php


Line Number: 11


login_view



    $loginEmail = array('placeholder' => "Email", 'name' => "loginEmail");
$loginPassword = array('placeholder' => "Wachtwoord", 'name' => "loginPassword");
$loginSubmit = array('name' => "loginSubmit", 'class' => "btn", 'value' => "Inloggen");
$loginForgot = array('name' => "loginForgot", 'class' => "link", 'value' => "Wachtwoord vergeten?");


echo form_open('login/login', array('class' => 'grid-100 formc'));
echo form_input($loginEmail);
echo form_password($loginPassword);
echo form_submit($loginSubmit);
echo form_submit($loginForgot);
?>


login_controller





Class Login extends CI_Controller{
function index(){
$data['content'] = 'login_view';
$this->load->view('templates/template', $data);
}



function login(){
$this->load->model('login_model');
$query = $this->login_model->validate();

if($query){
$data = array(
'username' => $this->input->post('loginEmail'),
'loggedin' => true

);


$this->session->set_userdata($data);
redirect('profile/myprofile');
}
}

}

?>



login_model




Class Login_model extends CI_Model{

function validate(){
$this->db->where('email', $this->input->post('loginEmail'));
$this->db->where('password', md5($this->input->post('loginPassword')));


$query = $this->db->get('tbl_users');

if($query->num_rows == 1){
return true;
}
}

}


?>


autoload.php



$autoload['libraries'] = array('database', 'session');


What am I missing here?


Answer




You don't have a constructor, in your login controller:



public function __construct() {        
parent::__construct();
}

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...