2013-10-01 59 views
1

我有兩個表Symfony2中創建左加入

1)CMS

2)cms_translations

表1)CMS

id 
url 
status 

表2)cms_translations

object_id 
title 
lang_id 

那麼什麼是左連接查詢在twig文件中顯示兩個表值?

,這是通過查詢我

$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 " 
    ); 

完成,這是由我完成的代碼顯示在index.html.twing文件

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

{{ entity.Title }} 則無法打印如何在twing文件中打印cms_translations.title?

如何從第二個表中的HTML文件打印值?

+0

'從儀表板\ CmsBundle \實體\ Cms'?真? –

回答

1

的DQL:

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

這確保了轉譯在CMS對象加載。

然後在樹枝模板:

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