Closed
Description
Wouldn't it be better to recommend an unmapped field ('mapped'=>false
) for the file upload at https://symfony.com/doc/current/controller/upload_file.html ?
Advantages:
- Would mitigate the hassle with String<=>File conversion (see [Upload File]: Doctrine Listener vs. view transformer for File<=>String conversion #11390 )
- The main benefit of mapping is that on an "edit profile" form the form fields get prefilled with the current database values. But in this case, it doesn't make sense for the user to change the string (=file path) in the database, since the file wouldn't exist! So the real way to "edit" an uploaded file is to upload a new one (which should then overwrite the existing one in the controller).
- Would solve The form's view data is expected to be an instance of class Symfony\Component\HttpFoundation\File\File, but is a(n) string. You can avoid this error by setting the "data_class" option to null or by adding a view transformer that transforms a(n) string to an instance of Symfony\Component\HttpFoundation\File\File. EasyCorp/EasyAdminBundle#2356