Sonata Media Gallery

I am trying to create a website with Symfony. So I installed SonataAdminBundle and SonataMediaBundle.

And I have a question about the sonata media. I created a gallery with a lot of images in it and I don't know how I can access it from my controller.

How can I get my media (images) contained in my gallery to display in my template?

thanks for the reference!

EDIT: I solved my problem!

So, in my template, I:

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

      

+3


source to share


1 answer


Usually a Gallery or Media object is associated with other objects and we retrieve them from their relationship. for example, from the owner of the gallery or related funds to the product. after getting the transfer media object (image in this case) into template (twig or php) and use the sonata media helpers to render them.



0


source







All Articles