Php 使用vich_image One保存表单

Php 使用vich_image One保存表单,php,symfony,vichuploaderbundle,Php,Symfony,Vichuploaderbundle,形式 图像形式 class KeywordType extends AbstractType{ public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('title','text') ->add('logo',new ImageType()) 何时保存表单 得到 我在关键字中添加了数组解析器 Expected valu

形式

图像形式

class KeywordType extends AbstractType{
public function buildForm(FormBuilderInterface $builder, array $options)
{

    $builder
        ->add('title','text')
        ->add('logo',new ImageType())
何时保存表单 得到

我在关键字中添加了数组解析器

Expected value of type "KeywordsBundle\Entity\Image" for association field "Mea\KeywordsBundle\Entity\Keyword#$logo", got "array" instead.
所以得到错误


关联字段“KeywordsBundle\Entity\Keyword#$logo”的类型“KeywordsBundle\Entity\Image”的预期值改为“Symfony\Component\HttpFoundation\File\UploadedFile”。

添加此项时,我发现一个错误,Form ImageType没有默认值。省工

  public function setLogo($logo)
    {

        if(is_array($logo))
            $logo = reset($logo);
        $this->logo = $logo;
    }
Expected value of type "KeywordsBundle\Entity\Image" for association field "Mea\KeywordsBundle\Entity\Keyword#$logo", got "array" instead.
  public function setLogo($logo)
    {

        if(is_array($logo))
            $logo = reset($logo);
        $this->logo = $logo;
    }
   /**
     * @param OptionsResolverInterface $resolver
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'Mea\KeywordsBundle\Entity\Image'
        ));
    }