Answer the question
In order to leave comments, you need to log in
Symfony form builder with multiple photo upload?
1. Built a form for adding an ad, the Offer entity.
2. Added photo upload, File entity (AJAX upload returns photo ID).
3. How to create OfferImage entities after validating and adding the Offer entity?
Added the Offer entity to the form:
$builder->add('images', 'collection', array(
'type' => new OfferImage(),
));
{% for image in form.images %}
{{ form_widget(image) }}
{% endfor %}
<input type="file" name="pics" multiple>
Answer the question
In order to leave comments, you need to log in
If you upload OfferImage separately, then you need to bind them to Offer.
At this point, you are creating an Offer creation form that creates or deletes an OfferImage. (parameters allow_add and allow_delete) On the contrary,
you need to bind existing OfferImages.
// Тут хоть аяксом, хоть вручную выбираете загруженные OfferImage,
// Потому что они уже есть.
$builder->add('images');
$builder->add('images', 'collection', array(
'type' => new OfferImageType()
));
// Где в OfferImageType $builder->add('file'); // И тут выбираем файл из списка
$builder->add('images', 'collection', array(
'type' => new OfferImageType(),
'allow_add' => true,
));
$builder->add('file', 'file');
// или $builder->add('file', new FileType()); раз он привязан так.
// и в FileType уже $builder->add('file', 'file');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question