Symfony小枝数组键显示


symfony twig array key display

我试图使用数组索引从数据库获取数据,但我不想迭代。

内容表:

|id|      content          |active
|1|this is first content   |yes
|2| This is secound Content| yes

Controller.php:

$em = $this->getDoctrine()->getManager();
$entities= $em->getRepository('TestCMSBundle:Content'Content')->GetContents();
return $this->render('TestCMSBundle:Default:index.html.twig', array('entities' => $entities));

mytwig:

{{ entities.content[0] }}

一些其他内容....哇啦

{{ entities.content[1]}}

但是我似乎看不懂内容。

错误:在TestCMSBundle:index.html中,键为"0,1"的数组的键"content"不存在。

请,我不想像这样在循环中迭代:

{% for entity in entities %}
{{ entity.content}}
{%endfor%}

你应该用圆点代替括号:

entities.0.content