Sonata Media: The file could not be found

半城伤御伤魂 提交于 2020-01-05 06:49:28

问题


I'm trying to attach an image to an Entity but when I submit the form, an error is displayed saying: The file could not be found.

Here is my code to build the form:

$builder
    ->add('email', 'email', array('label' => 'Email'))
    ->add('name', 'text', array('label' => 'Name'))
    ->add('image', 'sonata_media_type', array('label' => 'Image', 'provider' => 'sonata.media.provider.image', 'context'  => 'default'))
;

What am I doing wrong?

Thanks


回答1:


First, you need to 'link' your Entity to the SonataMediaBundle :

/**
 * @ORM\ManyToOne(targetEntity="Application\Sonata\MediaBundle\Entity\Media")
 * @ORM\JoinColumn(name="image", referencedColumnName="id")
 */
private $image;

And then in your Admin, in the configureFormFields(FormMapper $formMapper) :

->add('image', 'sonata_type_model_list', array('label' => 'Image', 'required' => false)))

In my projects, I've made it like that :)



来源:https://stackoverflow.com/questions/15590505/sonata-media-the-file-could-not-be-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!