问题描述:

Considers 2 entities : Game and Image ...

Game has the following fields : name, description and image which is linked to an Image object

Image has the following fields : name and url

I'm using Symfony2 formbuilder to add and edit Games records.

In the GameType class I'm building the formular in order to provide all images in database as a Choice List ... like that:

->add('image', 'entity', array(

'class' => 'MediaCollectionBundle:Image',

'query_builder' => function (ImageRepository $er) {

return $er->createQueryBuilder('u')->orderBy('u.nom', 'ASC');

},

'property' => 'nom',

'label' => 'nom de l\'image',

))

The view is provided in a twig file like this:

<div class="form-group">

{{ form_label(form.image, "Image", {'label_attr': {'class': 'col-sm-3 control-label'}}) }}

{{ form_errors(form.image) }}

<div class="col-sm-4">

{{ form_widget(form.image, {'attr': {'class': 'form-control'}}) }}

</div>

</div>

This displays the list of all images I have in database.

To validate the add/edit game form, I have to select one choice ..

But, I want to display dynamically the selected image (<img src=...>).

Is it possible ?

Thanks for your help :)

相关阅读:
Top