简体   繁体   English

在Twig模板中显示最后加入的实体列

[英]Display the last joined entity columns in Twig template

I'm making a website for performance monitoring, so every months people's fill their performances and this create a graph in JavaScript. 我正在建立一个用于性能监控的网站,因此每个月人们都会填写他们的性能,然后用JavaScript创建一个图表。

I did a ManyToOne relation between performances entity and users entity. 我在表演实体和用户实体之间建立了ManyToOne关系。 As you can see here: 如您所见:

I would like to display the performances of one user for example I use this code in Twig (and after I would like to know how to display the latest performances). 我想显示一个用户的表演,例如,我在Twig中使用了此代码(之后我想知道如何显示最新的表演)。

Entity performances: 实体表现:

在此处输入图片说明

  {% for user in users %} <h4>{{ user.username|upper }}</h4> <p>Ville: {{ user.performances.ville }}</p> <p>Taille: {{ user.performances.taille }}</p> {% endfor %} 

  /** * @ORM\\ManyToOne(targetEntity="Users", inversedBy="descriptions") * @ORM\\JoinColumn(name="users_id", referencedColumnName="id") */ private $user; 

But it don't works, can you guys help me? 但这不起作用,你们可以帮我吗?

If you want to access to the last item of your user.performances collection : 如果要访问user.performances集合的最后一项:

{% for user in users  %}
    <h4>{{ user.username|upper }}</h4>
    <p>Ville: {{ user.performances.last.ville  }}</p>
    <p>Taille: {{ user.performances.last.taille  }}</p>
{% endfor %}

You can do the same with first for the first item. 你可以做同样的first的第一个项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM