我希望在 cakephp 的控制器中验证。虽然我的验证在模型中运行良好,但我希望在控制器中验证它而不是模型。
我做了什么来验证控制器。
$validates = array('email' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'A email is required'
),
'isUnique' => array(
'rule' => array('notEmpty'),
'message' => 'This email is already registered'
),
'email' => array(
'rule' => array('email'),
'message' => 'Enter valid mail address'
)
));
if ($this->User->validates($validates)) {
die("Action can be performed as validated !! Fields are correct");
} else {
die("Action can't be performed !! Fields are in-correct");
}
无论字段是否正确,它总是让我处于正确的状态。请帮忙