Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony:循环在细枝模板中不起作用_Php_Symfony - Fatal编程技术网

Php Symfony:循环在细枝模板中不起作用

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

我已经在一个存储库中创建了e simple函数,并像下面这样将其传递给控制器

控制器

...

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 %}

基础知识。至少您会知道给定给渲染函数的数组的含义。安东值得投票。