简体   繁体   中英

Sonata media gallery

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 %}

Usually Gallery or Media entity are related to other entities and we retrieve them from their relation. eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM