Cakephp 3.0独特的电子邮件

时间:2015-04-08 11:49:21

标签: cakephp unique cakephp-3.0

我对cakephp很新,我需要帮助设置唯一的电子邮件和错误消息。这就是我的模型的样子。谢谢!

 <?php
 namespace App\Model\Table;

 use Cake\ORM\Table;
 use Cake\Validation\Validator;

  class UsersTable extends Table
  {

public function validationDefault(Validator $validator)
{
    return $validator
        ->notEmpty('email', 'A email is required')
        ->add('email', 'valid' , ['rule'=> 'email'])
        ->requirePresence('email','create')

        ->notEmpty('password', 'A password is required')
        ->notEmpty('role', 'A role is required')
        ->add('role', 'inList', [
            'rule' => ['inList', ['admin', 'author']],
            'message' => 'Please enter a valid role'
        ]);
}

}

0 个答案:

没有答案