cakePHP唯一电子邮件用户名

cakePHP唯一电子邮件用户名,cakephp,Cakephp,我只是需要一点帮助来识别用户的电子邮件,这也是数据库中的用户名,我在模型中使用了“isUnique”,但由于某些原因,它没有给出错误消息,它仍然注册用户。请有人给我一点帮助这里是代码 模型 看法 验证规则的数组声明错误。 它们的级别错误,因此无效。 例如,电子邮件密钥使用两次 请根据文档进行更正-并使用正确的1制表符缩进。 这将使它们既正确又可读,并且很容易防止您在上面犯的错误。请注意大小写,usersController应该是usersController,但是-Form->create是一

我只是需要一点帮助来识别用户的电子邮件,这也是数据库中的用户名,我在模型中使用了“isUnique”,但由于某些原因,它没有给出错误消息,它仍然注册用户。请有人给我一点帮助这里是代码

模型

看法


验证规则的数组声明错误。 它们的级别错误,因此无效。 例如,电子邮件密钥使用两次

请根据文档进行更正-并使用正确的1制表符缩进。
这将使它们既正确又可读,并且很容易防止您在上面犯的错误。

请注意大小写,usersController应该是usersController,但是-Form->create是一个小写的方法。您还应该清理代码,或者编写更干净的代码。这很难理解。另外:您应该经常提到您正在使用的确切cakephp版本。
App::uses('AuthComponent','Controller/Component');
class User extends AppModel {

     public $validate = array(
        'email' => 'email',
        'email' => array(
        'required' => array(
        'rule' => array('notEmpty'),
        'message' => 'Please enter a valid email address for username',
        'unique' => array(
        'rule' => 'isUnique',
        'message' => 'Please enter another email, this one is already taken'
       )
       )
       ),
        'password' => array(
        'required'=> array(
        'rule' => array('notEmpty'),
        'message' => 'Please enter a valid password',

        'rule' => array('minLength','8'),
        'message' => 'Please enter minimum 8 characters'
       )
       )
    );

       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;
    }


 }
**CONTROLLER**

<?php


class usersController extends AppController
{
    public function beforeFilter() {
    parent::beforeFilter();
    $this->Auth->allow('add');
}
    var $name = 'Users';




    public function add()
     {

    if (!empty($this ->data))
    {
        $this->User->create();
        if ($this->User->save($this->data))
        {
            $this->Session->setFlash('Thank you for registering');
            $this->redirect(array('action'=>'index'));
        }
        else
        {
            // Make the password fields blank
            unset($this->data['User']['password']);
            unset($this->data['User']['confirm_password']);

            $this->Session->setFlash('An error occurred, try again!');
        }
    }


}

    function index()
    {

    }
    public function login() {
        if ($this->request->is('post')) {
            if ($this->Auth->login()) {
                return $this->redirect($this->Auth->redirectUrl());
            }
            $this->Session->setFlash(__('Invalid username or password, try again'));
        }
    }

    public function logout() {
        return $this->redirect($this->Auth->logout());
      }
}
<h2>End a problem registration</h2>
        <p>Please fill out details to register</p>

<?php
        echo $this->Form->Create('User',array('action' => 'add'));
        echo $this->Form->input('title');
        echo $this->Form->input('name');
        echo $this->Form->input('surname');
        echo $this->Form->input('email');
        echo $this->Form->input('password');
        echo $this->Form->input('password');
        echo $this->Form->end('Register');