ForumBundle\Entity\User:
group_sequence: [User, Admin]
properties:
login:
- NotIdenticalTo:
value: ROOT
message: 'Login must be different from ROOT!'
phone:
- NotBlank:
message: 'Phone must be present!'
groups: [Admin]
granted_by:
- NotBlank:
message: 'Your promotor must be present!'
groups: [Admin]
和
public function indexAction(Request $request)
{
$user = new User();
$user->setLogin('ROOT');
$errors = $this
->get('validator')
->validate(
$user,
null,
array('Admin', 'User')
);
if (count($errors) > 0) {
return new Response(
(string) $errors
);
}
return new Response('ok!');
}
为什么屏幕上出现3个错误?在我看来,首先应该验证用户组,它应该给出错误,所以我不应该再看到任何错误。