Twig中的输出数组 [英] Output array in Twig
本文介绍了Twig中的输出数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图将数据库中的数组输出到屏幕。
在我的实体中:
I trying to output an array from the database to the screen. In my entity:
/**
* @ORM\Column(type="array", nullable=true)
*/
private $category;
在我的树枝模板中:
{% for category in user.profile.category %}
{{ category }}
{% endfor %}
错误: ...中的数组到字符串的转换
我的错误在哪里?
推荐答案
TWIG不知道您要如何显示表格。
TWIG doesn't know how you want to display your table.
顺便说一句,您应该考虑将变量命名为 $ categories
而不是 $ category
,因为您的表包含多个类别。
By the way, you should consider naming your variable $categories
instead of $category
, as you table contains several categories.
然后尝试以下操作:
{% for category in user.profile.categories %}
{{ category }}
{% endfor %}
如果我的回答无济于事,请给我们您数组的结构(表中是否有任何键或子数组,还是只是列表? )
If my answer doesn't help, please give us the structure of your array (is there any keys or sub-arrays in you table or is it just a list?)
这篇关于Twig中的输出数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文