簡體   English   中英

Symfony:循環在樹枝模板中不起作用

[英]Symfony: Loop does not work in twig template

我在存儲庫中創建了一個簡單的函數,並將其傳遞給這樣的控制器

控制器

...

public function repositoryAction() {

$em = $this->getDoctrine()->getManager();
$user = $em->getRepository('AppBundle:User')->findAllOrderedByName();



return $this->render('dashboard/repository.html.twig',array('user'=>$user));


}

與下面的代碼行

return $this->render('dashboard/repository.html.twig',array('user'=>$user));

我將數組傳遞給視圖。

這是樹枝模板中的循環

{% for user in profile %}
{{ profile.name }}
{% endfor %}

這是錯誤:

Variable "profile" does not exist in dashboard/repository.html.twig at line 44

我做錯了什么?

我認為你應該這樣做:

{% for profile in user %}
{{ profile.name }}
{% endfor %}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM