Symfony 3组序列不起作用

时间:2016-04-21 15:01:22

标签: symfony

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个错误?在我看来,首先应该验证用户组,它应该给出错误,所以我不应该再看到任何错误。

0 个答案:

没有答案