简体   繁体   中英

Symfony2 create left join

I have two table

1) cms

2) cms_translations

table 1) cms

id
url
status

table 2) cms_translations

object_id
title
lang_id

then what is left join query for display both table value in twig file?

this is query done by me

    $q = $em->createQuery("SELECT c , d FROM Dashboard\CmsBundle\Entity\Cms c 
    JOIN c.translations d 
    WITH c.id = d.object AND c.status = 1
    GROUP BY c.sortOrder 
    ORDER BY c.sortOrder ASC "
    );

and this is code done by me for display in index.html.twing file

    {% for entity in enitity_cms %}
    <a href="{{ path('_cmsAboutUs' , { slug : entity.url }) }}" >{{ entity.Title }}</a>
    {% endfor %}    

but not print in {{ entity.Title }} then how to print cms_translations.title in twing file?

How do I print value in html file from second table?

The DQL:

SELECT c , d FROM Dashboard\CmsBundle\Entity\Cms c 
JOIN c.translations d WHERE c.status = 1

This ensures that the translations are loaded in the Cms object.

Then in the twig template:

{% for entity in entity_cms %}
  {% for translation in entity.translations %}
     <a href="{{ path('_cmsAboutUs' , { slug : entity.url }) }}" >{{ translation.Title }}</a>
  {% endfor %}    
{% endfor %}    

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