symfony,无法在嵌入的表单+文件上传递验证

时间:2014-07-25 21:10:46

标签: forms file validation symfony

尝试嵌入一个集合或只是一个包含文件字段的简单类型,但两者都会导致同样的问题。在帖子上,UploadedFile存在,但验证失败。 “这个值无效。”

全天都在抨击我,有人吗?

公司表格:

简单嵌入文件:

$builder->add('logo', new FileType(), [
    'label' => 'Logo',
    'required' => false,
    'attr' => [
        'accept' => 'image/*',
    ]
]);

带文件的收藏:

$builder->add('images', 'collection', array(
    'type' => new FileType(),
    'data' => [
        new File(),
        new File(),
        new File(),
    ],
));

文件类型:

class FileType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $data = $builder->getData();

        $builder->add('file', 'file', [
            'label' => 'Bestand',
        ]);

        $builder->add('submit', 'submit', [
            'label' => 'Save',
        ]);
    }

    public function getName()
    {
        return 'file';
    }

    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'Acme\DemoBundle\Entity\File',
        ));
    }
}

该实体具有从公司到文件的一对多功能。

一切正常,但提交表单时。这两个字段都有“此值无效”。错误。

这是clientData preSubmit的转储:

 'logo' => 
    object(Symfony\Component\HttpFoundation\File\UploadedFile)[13]
      private 'test' => boolean false
      private 'originalName' => string 'etc.jpg' (length=13)
      private 'mimeType' => string 'image/jpeg' (length=10)
      private 'size' => int 103843
      private 'error' => int 0
  'images' => 
    array (size=3)
      0 => 
        object(Symfony\Component\HttpFoundation\File\UploadedFile)[14]
          private 'test' => boolean false
          private 'originalName' => string 'Screen Shot 2014-07-24 at 17.15.30.png' (length=38)
          private 'mimeType' => string 'image/png' (length=9)
          private 'size' => int 84102
          private 'error' => int 0
      1 => null
      2 => null

对我来说似乎完全没问题!

0 个答案:

没有答案