我准备了一些注册表(最简单的),在我的模型中,我为电子邮件字段准备了一些验证:
'email' => array(
'mail' => array(
'rule' => array('email', true),
'required' => false,
'message' => 'Not correct e-mail!'),
'unique' => array(
'rule' => 'isUnique',
'message' => 'E-mail was registered!'))
但规则是独特不起作用 另外我将MySQL字段电子邮件更改为唯一,但仍然无法正常工作 我使用CakePHP 2.3.7
问题是我们在模型中使用翻译行为。
查询:
SELECT COUNT(DISTINCT(`User`.`id`)) AS count FROM `sometable`.`users` AS `User` INNER JOIN `sometable`.`i18n` AS `I18nModel` ON (`User`.`id` = `I18nModel`.`foreign_key` AND `I18nModel`.`model` = 'User' AND `I18nModel`.`locale` = 'pl') WHERE `User`.`email` = 'kicaj@kdev.pl'
现场电子邮件未翻译。
答案 0 :(得分:1)
试试这个。
array(
'email' => array(
'notEmpty' => array(
'rule' => 'notEmpty',
'message' => 'Provide an email address'
),
'validEmailRule' => array(
'rule' => array('email'),
'message' => 'Invalid email address'
),
'uniqueEmailRule' => array(
'rule' => 'isUnique',
'message' => 'Email already registered'
)
)
);
答案 1 :(得分:1)
我复制了你的代码并将其粘贴在我的模型中,它运行良好!我不认为它有任何错误。我刚刚在你的代码后添加了分号。这是我检查过的代码:
'email' => array(
'mail' => array(
'rule' => array('email', true),
'required' => false,
'message' => 'Not correct e-mail!'),
'unique' => array(
'rule' => 'isUnique',
'message' => 'E-mail was registered!')),
我认为还会有其他错误!!