我有一個在視圖中創建的登錄表單。然後在我的控制器中,我試圖加載我的模型,但似乎沒有加載。在stackoverflow上查了幾個答案,幾乎所有人都說自動加載模型,導入數據庫庫等等。我這樣做,但我仍然得到錯誤CodeIgniter - 在非對象上調用成員函數模型()
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');
缺少什麼我在這裏?
這樣做的伎倆,謝謝! – mXX
加載模型時出現相同的錯誤消息。我已經嘗試添加上面提到的代碼,但它仍然是相同的。請幫忙嗎? – Salman