我有一个包含两个字段的未绑定表单,我想验证。我想在两个字段和我的两个自定义验证器 MyFile 和* UploadConstraints *上使用内置的 NotBlank 。问题是我可以让所有三个人一起工作。在 NotBlanks()之前调用 UploadConstraints ,如果我评论 UploadConstraints 附件约束不会触发,我使用 UploadConstraints < / em>引用这两个字段。
$builder
->add('country', 'entity',array(
'class' => 'WarrDigicelBundle:Country',
'property' => 'name',// display of countries
'label' => 'Country:',
'empty_value' => '',
'empty_data' => null,
'required' => false,
'constraints' => new NotBlank(),
))
->add('attachment', 'file',array(
'label' => 'Upload:',
'required' => false,
'constraints' => new NotBlank(),
'constraints' => array( new Constraints\MyFile())
))
->add('Upload File', 'submit')
;
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => null,
'cascade_validation' => true,
'constraints' => array( new Constraints\UploadConstraints())
));
}