2012-01-27 53 views
0

我如何才能找到從資料庫中的記錄控制器:如何找到從倉庫記錄

$em = $this->getDoctrine()->getRepository('ShopMyShopBundle:Product')->find($value); 

我可以做這樣的事情的模板?

{{ em.name }} 
+0

很難理解你在問什麼。 – webbiedave 2012-01-27 23:37:20

+0

你知道什麼?熱將數據從存儲庫傳遞到模板? – smoreno 2012-01-28 05:14:40

回答

0

在控制器:

$em = $this->get('doctrine')->getEntityManager(); 
$product = $em->getRepository('ShopMyShopBundle:Product')->find($value); 

你不能在模板做到這一點。歡迎閱讀documentation

1

這取決於$value中的內容。方法find()將由id finb。如果要通過例如slug進行搜索,則必須調用方法findBySlug()或等效的findOneBySlug()

相關問題