Php 验证Symfony2实体选择字段
我正在尝试验证symfony 2.3项目中的表单, 因此,我有一个“客户”字段:Php 验证Symfony2实体选择字段,php,validation,symfony,Php,Validation,Symfony,我正在尝试验证symfony 2.3项目中的表单, 因此,我有一个“客户”字段: $builder ->add('customer', 'entity', array('property'=> 'item', 'multiple' => true, 'expanded' => true, 'class' =>
$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');
}));
我试图在用户未选择任何内容时返回错误,因此我执行以下操作:
properties:
customer:
- Choice: { min: 1, minMessage: 'message' }
或
和其他事情,但没有任何效果,一个我做错了什么??
在文档中,他们说我们可以使用数组,但这也不起作用
实际上,Symfony返回:
必须在约束选择上指定选项或回调
对于选项验证程序,您需要从以下文档中指定具有可用允许选项的数组或回调函数:
此约束用于确保给定值是给定有效选项集之一。它还可用于验证项目数组中的每个项目是否为这些有效选项之一
您可以使用的可能是验证器:
customer:
- Count:
min: 1
max: 99
minMessage: "Min message"
maxMessage: "You cannot specify more than {{ limit }}"
对于选项验证程序,您需要从以下文档中指定具有可用允许选项的数组或回调函数:
此约束用于确保给定值是给定有效选项集之一。它还可用于验证项目数组中的每个项目是否为这些有效选项之一
您可以使用的可能是验证器:
customer:
- Count:
min: 1
max: 99
minMessage: "Min message"
maxMessage: "You cannot specify more than {{ limit }}"
这帮不了我这帮不了我