Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2: Edit file upload

I am using the cookbook article from symfony.com to implement a file upload option for images.

Now I want to load up other images to the entity.

The default strategy for editing is: 1. Fetch out of DB 2. Inject into Form 3. Persist

Somehow this strategy doesn't work anymore when using file uploads (doctrine doesn't execute the events)

What else could I do to make the articles with picture editable?

like image 525
bodokaiser Avatar asked Apr 01 '12 08:04

bodokaiser


1 Answers

The cookbook does not handle updates, in particular in the case where only the file changes.

In this case, the PreUpdate event is not triggered, so you need to trigger $entity->preUpload() manually before the $em->persist($entity), so that the file upload gets handled in any case (preUpload will alter $entity->path so the persisting will occur)

like image 71
mlarcher Avatar answered Sep 28 '22 00:09

mlarcher