Php 每次尝试登录或按login时,我都会被run方法卡住
我正在尝试通过我的登录页面登录。每次我在字段中输入值或只按login键时,我都会注意到在我的浏览器上,它在run方法处停止,我的页面留空 我的数据库有两列,实际标题为“用户名”和“密码”。 我似乎不知道是什么原因造成的 这是我的login_model.php文件:Php 每次尝试登录或按login时,我都会被run方法卡住,php,mysql,login,Php,Mysql,Login,我正在尝试通过我的登录页面登录。每次我在字段中输入值或只按login键时,我都会注意到在我的浏览器上,它在run方法处停止,我的页面留空 我的数据库有两列,实际标题为“用户名”和“密码”。 我似乎不知道是什么原因造成的 这是我的login_model.php文件: <?php class Login_Model extends BaseModel { public function __contruct(){ parent:: __construct(); } p
<?php
class Login_Model extends BaseModel {
public function __contruct(){
parent:: __construct();
}
public function run() {
$sth = $this->database->prepare("SELECT id FROM users WHERE
Username = :username AND Password = :password");
$sth->execute(array(
':username' => $_POST['username'],
':password' => $_POST['password']
));
//$data = $sth->fetchAll();
$count = $sth->rowCount();
if ($count > 0){
//login
Session::init();
Session::set('loggedIn', true);
header('location: ../controllers/dashboard');
} else {
//show error
header('location: ../login/loginIndex');
}
}
}
?>
这是控制器的login.php文件中的内容:
<?php
class Login extends BaseController {
function __construct(){
parent::__construct();
}
//this is to avoid interference with the page that I want to call
function index() {
$this->view->render('../views/login/loginIndex');
}
function run(){
$this->model->run();
}
// public function other() {
// require '../models/loginModel.php';
// $model = new loginModel();
// }
}
错误消息表示您在Login
中没有Login\u Model
的实例
尝试在Login
中的构造函数上方插入private$model
,然后在构造函数中使用$model=new Login\u model()
白色死亡屏幕:错误检查\显示关闭,打开它们以查看错误。在php页面顶部添加:ini_集('display_errors','On');ini_集('html_错误',0);错误报告(-1)代码>所以我尝试了您的方法,将私有$model放在函数_construct()之上,然后放在构造函数$model=new Login_model();。我收到了以下错误。。。致命错误:在第13行的/apps/help-i-need-a-tutor/controllers/Login.php中找不到类“Login\u Model”。然后我添加了require'../models/login_model.php';然后我得到了另一种表示致命错误的错误:在第24行的/apps/help-I-need-a-tutor/controllers/login.php中对非对象调用成员函数run()。
<?php
class Dashboard extends BaseController {
function __construct(){
parent::__construct();
Session::init();
// You set the variable session: LoggedIn if they pass the condition
$logged = Session::get('loggedIn');
if ($logged == false){
Session::destroy();
header('location: ../login/loginIndex');
exit;
}
}
//this is to avoid interference with the page that I want to call
function index() {
$this->view->render('../views/dashboard/adminPage');
}
}