Key “path” for array with keys “” does not exist while dump says it does

独自空忆成欢 提交于 2019-12-06 02:14:12

问题


I'm currently working on a cms using symfony2 as the underlying framework and twig as the template engine.

My problem is the following:

While this

{% for image in images %}
    {{ dump(image.path is defined) }}
{% endfor %}

returns true for each element in the array,...

...but this one

{% for image in images %}
    {{ image.path}}
{% endfor %}

throws an exeption.

Key "path" for array with keys "" does not exist

A twig-dump of the images-array returns this:

array(2) {
    [0]=> object(stdClass)#2759 (9) {
        ["id"]=> string(5) "17795"
        ["typ"]=> string(3) "jpg"
        ["path"]=> string(10) "Tulips.jpg"
    }
    [1]=> object(stdClass)#2874 (9) {
        ["id"]=> string(5) "17796"
        ["typ"]=> string(3) "jpg"
        ["path"]=> string(14) "Hydrangeas.jpg"
    }
}

This seems to be paradox to me and i really don't understand this. Has someone an Idea? I would be very thankful, deadlines are coming... :/


回答1:


I think u created multidimensional array. Try foreach loop in twig template for image also

{% for image in images %}
    {% for i in image %}
       {{ i.datei }}
    {% endfor %}
{% endfor %}


来源:https://stackoverflow.com/questions/20149954/key-path-for-array-with-keys-does-not-exist-while-dump-says-it-does

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!