Php Symfony:循环在细枝模板中不起作用
我已经在一个存储库中创建了e simple函数,并像下面这样将其传递给控制器 控制器Php Symfony:循环在细枝模板中不起作用,php,symfony,Php,Symfony,我已经在一个存储库中创建了e simple函数,并像下面这样将其传递给控制器 控制器 ... public function repositoryAction() { $em = $this->getDoctrine()->getManager(); $user = $em->getRepository('AppBundle:User')->findAllOrderedByName(); return $this->render('dashboard/re
...
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 %}
基础知识。至少您会知道给定给渲染函数的数组的含义。安东值得投票。