5

I try to make a web site with Symfony. So I installed SonataAdminBundle and SonataMediaBundle.

And I have a question about Sonata media. I created a gallery with a lots of image media in it and I don't know how I can access it from my Controller.

How can I get my media (image) contained in my gallery for show them in my template?

thx for help !

EDIT: I solved my problem !

So in my template I do:

{% for img in MyEntity.gallery.galleryHasMedias %}
    <img src={% path img.media, 'reference'%}>
{% endfor %}
Tiket_dev
  • 141
  • 1
  • 11

1 Answers1

0

Usually Gallery or Media entity are related to other entities and we retrieve them from their relation. e.g. from owner of a gallery or related medias to a product. after fetching pass media object(image in this case) to template(twig or php) and use sonata media helpers to display them.

Erfan
  • 1,132
  • 15
  • 21