英文:
Error symfony Key "" for array with keys "..." does not exist
问题
I need some help with this error
Key "dateFinValidite" for array with keys "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22" does not exist.
I use this here:
{{ include('/Unite/inc.listUnites.html.twig', {'unites': unites.dateFinValidite|filter(u => u > "now"|date('U'))}) }}
What I want is to show only available date.
I tried to make a loop of this include but that didn't work.
英文:
I need some help with this error
Key "dateFinValidite" for array with keys "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22" does not exist.
I use this here:
{{ include('/Unite/inc.listUnites.html.twig', {'unites': unites.dateFinValidite|filter(u => u > "now"|date('U'))}) }}
What I want is to show only avalaible date.
I tried to make a loop of this include but that didn't work.
答案1
得分: 0
unites
是一个数组,你正在尝试访问它的 dateFinValidite
属性,我假设这是该数组中每个条目的属性。这不是与Symfony或Twig相关的错误。这就是你收到这个错误的原因。
正确的代码应该类似于这样:
{% for unite in unites %}
{% if unite.dateFinValidite > "now"|date('U') %}
{{ include('/Unite/inc.unite_item.html.twig', {'unite': unite}) }}
{% endif %}
{% endfor %}
或者类似于这样:
{% for unite in unites|filter(unite => unite.dateFinValidite > "now"|date('U')) %}
{{ include('/Unite/inc.unite_item.html.twig', {'unite': unite}) }}
{% endfor %}
英文:
unites
is an array and you are trying to access his dateFinValidite
attribute of it which is, i assume, an attribute of each entry of this array. This is not an error related to symfony or twig.
This is why you get this error.
The proper code would be something like this :
{% for unite in unites %}
{% if unite.dateFinValidite > "now"|date('U') %}
{{ include('/Unite/inc.unite_item.html.twig', {'unite': unite) }}
{% endif %}
{% endfor %}
OR something like this
{% for unite in unites|filter(unite => unite.dateFinValidite > "now"|date('U')) %}
{{ include('/Unite/inc.unite_item.html.twig', {'unite': unite) }}
{% endfor %}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论