Twig 中的输出数组 [英] Output array in Twig

查看:19
本文介绍了Twig 中的输出数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将一个数组从数据库输出到屏幕.在我的实体中:

I trying to output an array from the database to the screen. In my entity:

/**
 * @ORMColumn(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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆