Error symfony Key "" for array with keys "…" does not exist

huangapple go评论63阅读模式
英文:

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 %}

huangapple
  • 本文由 发表于 2023年5月10日 20:08:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76218238.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定