我将 Silex 用于一个小型项目,但我不确定如何验证两个匹配的密码字段,也不确定如何使用数据库连接检查电子邮件的唯一性。我无法在 SF2 文档中弄清楚。
可能有人可以给我一个提示或样本吗?
提前致谢
if ('POST' === $user->getMethod()) {
$constraint = new Assert\Collection(array(
'name' => array(new Assert\NotBlank(array('message' => 'Name shouldnt be blank'))),
'username' => array(new Assert\NotBlank(), new Assert\MinLength(3)),
'email' => array(new Assert\NotBlank(), new Assert\Email()),
'password' => array(new Assert\NotBlank(), new Assert\MinLength(6)),
'password2' => array(new Assert\NotBlank(), new Assert\MinLength(6)),
'terms' => array(new Assert\True()),
));
$errors = $app['validator']->validateValue($user->request->all(), $constraint);
if (!count($errors)) {
//do something
}
}