1
我對Symfony和Twig真的很陌生,我試圖從數據庫中獲取信息到樹枝模板或更好地對主頁說。模板中的數據庫對象
在控制器中,代碼如下所示。
$product= $this->getDoctrine()
->getRepository('AppBundle:Product')
->find($productID); // $productID is given with the slug.
我回到這一點:
return $this->render("default/index.html.twig" ,array("data"=>$product))
在樹枝模板我使用foreach循環
{% for datas in data %}
{{ datas.price }}
{% endfor %}
但它不工作。 我已經傾倒了數據,它看起來像這樣。 Dump
感謝
謝謝它的作品! – Kira
'data.id'也可以在對象的情況下工作 – DarkBee
@DarkBee是的,當你有一個對象時,你不能在'for循環中' –