The form's view data is expected to be an instance of class … but is a(n) string

前端 未结 2 478
旧巷少年郎
旧巷少年郎 2021-01-11 19:15

I am currently receiving the following error:

\"The form\'s view data is expected to be an instance of class Symfony\\Component\\HttpFoundation\\File

2条回答
  •  情歌与酒
    2021-01-11 19:57

    /**
     * @ORM\Column(type="string")
     *
     * @Assert\NotBlank(message="Please, upload the song as a MP3 file.")
     * @Assert\File(mimeTypes={ "audio/mpeg", "audio/wav", "audio/x-wav", "application/octet-stream" })
     */
    private $file;
    

    You tell doctrine that you want to store a string, but you render an upload button in the form which send you a physic file which you do not want to store in your database at all. Instead you want to move the file from a temporary directory to your upload directory, and you want to remember the name of the file into the database wherefore you need this property which is a string.

    Best way is to follow this page

提交回复
热议问题