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
<?php
$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
<?php
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
<?php
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?
You don't have a constructor, in your login controller:
public function __construct() {
parent::__construct();
}
According to CodeIgniter docs
If you intend to use a constructor in any of your Controllers, you MUST place the following line of code in it: parent::__construct();
Refer CI Constructor for more.
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