验证 Symfony2 实体选择字段

Validation Symfony2 Entity Choice Field

我正在尝试验证 symfony 2.3 项目中的表单, 所以我有一个 'Customer' 字段:

$builder
    ->add('customer', 
          'entity', 
           array('property'=> 'item',
                 'multiple' => true, 
                 'expanded' => true, 
                 'class' => 'OrdersBundle:Customer', 
                 'required' => true, 'empty_value' => '',
                 'query_builder' => function(\Ella\OrdersBundle\Repository\CustomerRepository $er) {
            return $er->createQueryBuilder('q')->andWhere("q.is_delete = 0")->orderBy('q.item', 'asc');
        }));

我正在尝试 return 当用户没有 select 任何东西时出错,所以我这样做 :

properties:
    customer: 
        - Choice: { min: 1, minMessage: 'message' }

 properties:
    customer: 
        - NotBlank: 
            message: message

和其他东西,但没有任何效果,我做错了什么的想法?? 在文档中他们说我们可以使用数组,但这也不起作用...

实际上是 Symfony return :

Either "choices" or "callback" must be specified on constraint Choice

对于 Choice 验证器,您需要指定一个包含可用允许选项的数组或一个回调函数,来自文档:

This constraint is used to ensure that the given value is one of a given set of valid choices. It can also be used to validate that each item in an array of items is one of those valid choices.

您可以使用的可能是 Count 验证器:

customer:
        - Count:
            min: 1
            max: 99
            minMessage: "Min message"
            maxMessage: "You cannot specify more than {{ limit }}"