I'd like to use Uploadable to save some images (i.e. profile picture for users). I'm using many other Doctrine Extensions already (softdeletable, timestampable, blameable, etc.) so I thought it would be nice to use this one as well.
However, I don't know how to set up my Forms. The StofDoctrineExtensionsBundle documentation gives this example:
$document = new Document();
$form = $this->createFormBuilder($document)
->add('name')
->add('myFile')
->getForm()
;
//(...)
$uploadableManager->markEntityToUpload($document, $document->getMyFile());
In this example, is name the name of the Document or the name of the file?
Atlantic18/DoctrineExtensions's documentation adds a path, name, mimeType and size to an entity, to there is no myFile attribute.
Can anybody explain how to set up a Form for a Uploadable Doctrine entity? I couldn't find any documentation or good example that helped me further.
Entity
Like you've discovered, the documentation of DoctrineExtensions itself sheds some light on how to configure the Uploadable extension to use your entity.
Mainly by adding the
@Gedmo\Uploadableannotation to your entity and@Gedmo\UploadableFilePathto the property that will contain the file path ($filePathfor example).Form
With the
->add()method of the form-builder you add fields to the form. The first parameter specifies the property-name of the corresponding entity. So->add('myFile')would add a field for the property$myFile.What you need to do is add a (file) field to the form for the property that will contain the file path (
$filePathfor example), and mark that property:In other words:
myFilein your example should be replaced withfilePathin my example, and whatever the actual property is in your real code.