Cakephp:login什么都不做

Cakephp:login什么都不做,cakephp,cakephp-1.3,Cakephp,Cakephp 1.3,我从cakephp开始,尝试构建一个登录系统。问题是服务器响应我的登录请求,重新加载登录页面,没有任何消息,并且登录没有完成,因为它不允许我进入受保护的页面 这是我的用户表: mysql> show columns from users; +----------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default |

我从cakephp开始,尝试构建一个登录系统。问题是服务器响应我的登录请求,重新加载登录页面,没有任何消息,并且登录没有完成,因为它不允许我进入受保护的页面

这是我的用户表:

mysql> show columns from users;
+----------+------------------+------+-----+---------+----------------+
| Field    | Type             | Null | Key | Default | Extra          |
+----------+------------------+------+-----+---------+----------------+
| id       | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| email    | varchar(255)     | YES  |     | NULL    |                |
| password | varchar(255)     | YES  |     | NULL    |                |
| role     | varchar(20)      | YES  |     | user    |                |
| created  | datetime         | YES  |     | NULL    |                |
| updated  | datetime         | YES  |     | NULL    |                |
| username | varchar(255)     | YES  |     | NULL    |                |
+----------+------------------+------+-----+---------+----------------+
这是我的用户模型

<?php
App::uses('AuthComponent', 'Controller/Component');
class User extends AppModel{
    var $name = "User";    
    public function beforeSave($options = array()) {
        if (isset($this->data[$this->alias]['password'])) {
            $this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
        }
        return true;
    }
}
?>
class AppController extends Controller {
    public $components = array(
        'Auth' => array(
            'loginRedirect' => array('controller' => 'users', 'action' => 'index'),
            'logoutRedirect' => array('controller' => 'pages', 'action' => 'display', 'home')
        ),
        'Session'
    );

    public function beforeFilter() {
        $this->Auth->allow('index', 'view');

        $this->Auth->authorize = 'actions';
        $this->Auth->loginError = "This message shows up when the wrong credentials are used";
        $this->Auth->authError = "This error shows up with the user tries to access a part of the website that is protected.";

    }
}
这是我的用户控制器

<?php
class UsersController extends AppController{

    public function beforeFilter(){
        parent::beforeFilter();
        $this->Auth->allow('add', 'login');
    }

    public function index(){
        ...
    }

    public function view($id = null){
        ...
    }

    public function add(){
        if($this->request->is("post")){
            $this->User->create();
            if($this->User->save($this->request->data)){
                $this->Session->setFlash(__("The user has been saved"));
                return $this->redirect(array("action" => "index"));
            }
            $this->Session->setFlash(__("The user could not be saved. Please try again"));
        }
    }

    public function edit($id = null){
        ...
    }

    public function delete($id){
        ...
    }

    public function login(){
    }

    public function logout(){
        $this->redirect($this->Auth->logout());
    }
}
?>


为什么要使用一个非常古老的版本(1.3)-而不是当前稳定的2.4?因为我被命令:)但是你在这里展示的代码肯定是2.x版的。因此,我猜您实际上使用的是2.x版本,在这种情况下,您缺少了一个
AuthComponent::login()
call:我从这里开始(即1.3):