Can';t使用cakephp登录

Can';t使用cakephp登录,cakephp,authentication,Cakephp,Authentication,我无法在cakephp中使用Auth登录。在stackoverflow上有一些类似的帖子,但是这些答案似乎对我不起作用 我已经创建了一个类似的注册表单,它与Auth一起工作,但与登录一起工作, $this->Auth->login();在UsersController中返回false Auth使用正确的userModel,用户名字段更改为email。(注意:当我在任何地方使用用户名而不是电子邮件时,它也不起作用)。数据库有一个表用户,其中包含一封电子邮件和一个密码字段。密码字段使用:AuthCo

我无法在cakephp中使用Auth登录。在stackoverflow上有一些类似的帖子,但是这些答案似乎对我不起作用

我已经创建了一个类似的注册表单,它与Auth一起工作,但与登录一起工作, $this->Auth->login();在UsersController中返回false

Auth使用正确的userModel,用户名字段更改为email。(注意:当我在任何地方使用用户名而不是电子邮件时,它也不起作用)。数据库有一个表用户,其中包含一封电子邮件和一个密码字段。密码字段使用:AuthComponent::password()进行哈希/加密

//应用控制器

class AppController extends Controller {

    public $helpers = array('Html', 'Form');
    public $components = array(
        'Session',
        'Auth');

    public function beforeFilter() {
        $this->Auth->userModel = 'User';
        $this->Auth->fields = array('username' => 'email', 'password' => 'password');
        $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
        $this->Auth->loginRedirect = array('controller' => 'users', 'action' => 'index');
    }
}
class UsersController extends AppController{
  var $name = 'Users';
  var $helpers = array('Html', 'Form');

  function beforeFilter()
  {       
    parent::beforeFilter();
    // tell Auth not to check authentication when doing the 'register' action
    $this->Auth->allow('register');
  }

  function login(){
      if (isset($this->data['User'])) {
        $this->Auth->login();
        debug('tried');
      }
  }
//用户控制器

class AppController extends Controller {

    public $helpers = array('Html', 'Form');
    public $components = array(
        'Session',
        'Auth');

    public function beforeFilter() {
        $this->Auth->userModel = 'User';
        $this->Auth->fields = array('username' => 'email', 'password' => 'password');
        $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
        $this->Auth->loginRedirect = array('controller' => 'users', 'action' => 'index');
    }
}
class UsersController extends AppController{
  var $name = 'Users';
  var $helpers = array('Html', 'Form');

  function beforeFilter()
  {       
    parent::beforeFilter();
    // tell Auth not to check authentication when doing the 'register' action
    $this->Auth->allow('register');
  }

  function login(){
      if (isset($this->data['User'])) {
        $this->Auth->login();
        debug('tried');
      }
  }
//login.ctp

<?php
    echo $this->Form->create('User',array('action'=>'login'));
    echo $this->Form->input('email');
    echo $this->Form->input('password');
    echo $this->Form->end('Login');  

?>

//user.php

<?php
class User extends AppModel{

    var $name = 'User';
}
?>


我只使用了几天cakephp,所以这可能是一个简单的错误,但是我搜索了几个小时,仍然没有找到它。

设置属性,如
$this->Auth->userModel
$this->Auth->fields
在2.x中对您没有任何好处。您需要使用
$this->Auth->authenticate
属性来指定userModel和fields选项。有关更多信息,请阅读有关Auth配置的文章。

您使用的是哪个CakePHP版本?