Symfony 2 | Form exception when modifying an object that has a file(picture) field

前端 未结 3 1360
鱼传尺愫
鱼传尺愫 2021-02-01 06:51

I\'m using Symfony2. I have an entity Post that has a title and a picture field.

My problem : Everything is fine when I create a post, I have my picture e

3条回答
  •  -上瘾入骨i
    2021-02-01 07:30

    Please make below change in your PostType.php.

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
        ->add('title')
        ->add('picture', 'file', array(
                'data_class' => 'Symfony\Component\HttpFoundation\File\File',
                'property_path' => 'picture'
            )
        );
    }
    

提交回复
热议问题