[英]Fatal error: Call to a member function login() on a non-object in
遇到了我作為項目繼承的Web應用程序的問題,很遺憾,我無法跟蹤該錯誤。 似乎未加載模型,但我可能是錯的。 任何幫助都會很棒。
代碼是:
public function login()
{
//If request is post then user is trying to login, so process the login info
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
//Run the model method ::login
$login_successful = $this->User->login();
// check login status
if($login_successful) {
// if YES, then move user to dashboard/index (btw this is a browser-redirection, not a rendered view!)
header('location: ' . URL . 'passwords/index');
} else {
echo "Incorrect user / pass combination entered. Please try again.";
}
}
}
並且模型函數是:
public function login() {
$username = $_POST['data']['User']['username'];
$password = $_POST['data']['User']['password'];
$bind = array(
":username" => "$username",
);
$result = $this->select("users", "username = :username", $bind);
//Check the password returned from the db against the password entered
if (Bcrypt::checkPassword($password, $result[0]['password']) == true) {
Session::init();
Session::set('user_logged_in', true);
Session::set('user_id', $result[0]['id']);
Session::set('user_name', $result[0]['username']);
Session::set('user_permission', $result[0]['permission']);
Session::set('user_role', $result[0]['role']);
return true;
} else {
return false;
}
}
我也注意到控制器和模型都有一個名為login的函數。]
謝謝
原因是$this->User
不是有效的類實例。
確保它是一個對象。
嘗試
var_dump($this->User);
die();
//Run the model method ::login
$login_successful = $this->User->login();
您將看到那里沒有實例。
該怎么辦?
找到您希望模型初始化的位置。 檢查,為什么不是這樣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.