简体   繁体   English

symfony树枝数组键显示

[英]symfony twig array key display

I am trying to get the data from the db using array index however i do not want to iterate. 我试图使用数组索引从数据库中获取数据,但是我不想进行迭代。

content table: 内容表:

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

Controller.php: 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: mytwig:

{{ entities.content[0] }}

some other contents.... blah blah 其他一些内容....等等

{{ entities.content[1]}}

but i canot seems to get the content. 但我似乎无法获得内容。

Error: Key "content" for array with keys "0, 1" does not exist in TestCMSBundle:index.html.twig at line 80 错误:TestCMSBundle:index.html.twig中第80行的键“ 0、1”的数组的键“ content”不存在

please i do not want to iterate over the loop like: 请我不想像这样循环遍历:

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

您应该使用圆点而不是方括号:

entities.0.content

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM