Symfony 如何检索数组的值(字符串)';元素并使用它检索实体的属性值?

Symfony 如何检索数组的值(字符串)';元素并使用它检索实体的属性值?,symfony,twig,Symfony,Twig,如何检索数组元素的值(字符串)和实体的属性值?我试过这个: {% for item in items %} //item is an entity {% for column in columns %} //column is just an array with name of columns {% set columna = column.value %} {{ item.columna }} {% endfor %} {% endfor %} 试试这个: {% f

如何检索数组元素的值(字符串)和实体的属性值?我试过这个:

{% for item in items %} //item is an entity
  {% for column in columns %} //column is just an array with name of columns
    {% set columna = column.value %}
    {{ item.columna }}
  {% endfor %}
{% endfor %}
试试这个:

{% for item in items %} //item is an entity
  {% for column in columns %} //column is just an array with name of columns
    {% set columna = column.value %}
    {{ attribute(item, columna) }}
  {% endfor %}
{% endfor %}

我建议阅读。

如果要动态访问对象的属性,可以使用:


到底什么是不起作用的?你看到错误了吗?@谢谢!!,它可以工作,我忘了说
column.value
返回一个错误。只需
{{attribute(item,column)}}
就可以了。
{% for item in items %}
  {% for column in columns %}
    {{ attribute(item , column.value) }}
  {% endfor %}
{% endfor %}