Dre*_*ave 6 php nested symfony twig
Tl; DR Twig不会让我深入到嵌套对象中.
我有这个json_decoded对象的集合,其中有一个嵌套对象.当尝试输出嵌套对象的属性时,我得到一个错误,如:
""的项目"text"不存在
当我尝试转储嵌套对象时,我可以看到它很好......但是我无法访问它的任何属性.这是"整个"父对象的转储
Using this in my loop
{% for item in allFields %}
{{ dump(item) }}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)

这里是嵌套标签对象的转储,它在我的循环中使用{{dump(item.label)}}
Using this in my loop
{% for item in allFields %}
{{ dump(item.label) }}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)

我试图通过使用twig for循环获取标签类的text属性(和其他),如下所示:
{% for item in allFields %}
{{ item.label.text }}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
而且我在这里得到了错误
""的项目"text"不存在
这很奇怪。不过,有一次:这种情况发生在我身上,当时我EntityManager由于非常复杂的水合查询而内存不足。我认为数据的某些部分在这里会得到很多,并且您会收到此错误。
那么,这个列表中有多少项allFields?
为了解决这个问题,我建议您这样做:
{% for item in allFields %}
{{ item.label is null or item.label == "" ? "***EMPTY-LABEL***" : item.label.text }}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)