Php 为什么Symfony表单不能正常使用验证程序?

Php 为什么Symfony表单不能正常使用验证程序?,php,forms,symfony,Php,Forms,Symfony,我有收集模型: class EntityList { /** * @var Entity[] * @Assert\Count(min=1) * @Assert\Valid() */ private $entityList; // ... } 单一模式: class Entity { /** * @var int * @Assert\NotBlank() */ private $id;

我有收集模型:

class EntityList {
    /**
     * @var Entity[]
     * @Assert\Count(min=1)
     * @Assert\Valid()
     */
    private $entityList;

    // ...
}
单一模式:

class Entity {
    /**
     * @var int
     * @Assert\NotBlank()
     */
    private $id;

    /**
     * @var string
     * @Assert\NotBlank()
     */
    private $name;

    // ...
}   
收藏的形式:

class EntityListType extends AbstractType {
    public function buildForm(FormBuilderInterface $builder, array $options) {
        $builder->add('entity', CollectionType::class, [
            'entry_type' => EntityType::class, 
            'allow_add' => true,
            'property_path' => 'entityList',
        ]);
    }

    public function configureOptions(OptionsResolver $resolver) {
        $resolver->setDefault('data_class', EntityList::class);
    }

    public function getBlockPrefix() { 
        return null; 
    }
}
以及实体的形式:

class EntityType extends AbstractType {
    public function buildForm(FormBuilderInterface $builder, array $options) {
        $builder
            ->add('id', NumberType::class)
            ->add('name', TextType::class)
        ;
    }

    public function configureOptions(OptionsResolver $resolver) {
        $resolver->setDefault('data_class', Entity::class);
    }
}
集合的窗体在控制器中使用:

$form = $this->createForm(EntityListType::class);
$form->handleRequest($request);
我发送的包没有必需的标题(它是API):

那就接受它吧!方法
isValid
返回
true
。但是,如果使用
ValidationComponent
手动检查表单数据,则如下所示:

if ($form->isValid()) { // it's valid, okay
    echo $this->get('validator')->validate($form->getData()); // it's still not valid!
}
我看到了正确的错误(“需要标题”)!为什么?

p.S.Symfony 3.2,稳定

p.p.S.我现在暂时找到了解决办法。它是使用
$form->submit($request->request->all())而不是
$form->handleRequest($request)。但我不明白这个特征

if ($form->isValid()) { // it's valid, okay
    echo $this->get('validator')->validate($form->getData()); // it's still not valid!
}