这是我的 AppController.php
class AppController extends Controller {
public $components = array(
'Session',
'Auth' => array(
'loginAction' => array(
'controller' => 'students',
'action' => 'login'
),
'loginRedirect' => array('controller' => 'students', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'students', 'action' => 'login'),
'authError' => "You can't acces that page",
'authorize' => array('controller')
)
);
public function isAuthorized($student){
return TRUE;
}
}
这是我的 StudentController.php
class StudentsController extends AppController{
public function login(){
if($this->request->is('post')){
if($this->Auth->login()){
$this->redirect($this->Auth->redirect());
}else{
$this->Session->setFlash('Your username or password is incorrect');
}
}
}
public function logout(){
$this->redirect($this->Auth->logout());
}
}
这是我的 login.ctp
<h2>Login</h2>
<?php
echo $this->Form->create();
echo $this->Form->input('username');
echo $this->Form->input('password');
echo $this->Form->end('Login');
?>
在我的数据库中,表名是学生,其字段是用户名和密码。
但是每次我尝试用 登录时$this->Auth->login()
,它都会返回 false 并且显示密码错误的 flash 消息,我无法登录。