gpt4 book ai didi

symfony - 模板渲染过程中抛出异常

转载 作者:行者123 更新时间:2023-12-01 11:25:41 26 4
gpt4 key购买 nike

模板渲染过程中抛出异常

Catchable Fatal Error: Object of class Doctrine\ORM\PersistentCollection could not be converted to string

AppBundle:Dashboard:index.html.twig 第 46 行。

发生这种情况是因为 appointment.employees。有人可以解释一下吗?这是具有关系的实体:

/**
* @ORM\ManyToMany(targetEntity="LamecoEmployee")
* @ORM\JoinTable(name="appointment_lamecoemployee",
* joinColumns={@ORM\JoinColumn(name="appointment_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="lamecoempoloyee_id", referencedColumnName="id")}
* )
*/
protected $employees;

这是 View :

{% for appointment in appointments %}
<tr>
<td>{{appointment.startDate|date('H:i')}}</td>
<td>{{appointment.client.companyname}}</td>
<td></td>
<td>{{appointment.employees}}</td>
<td>{{appointment.description}}</td>
</tr> <br>
{% endfor %}

最佳答案

您必须遍历 appointment.employees,因为它是一个集合(与约会相同),或者将其转换为 twig 可以内联呈现的东西。

例如

{% for employee in appointment.employees %}
{{employee.name}}
{% endfor %}

或者,如果您只想要计数而不需要迭代:

{{appointment.employees|length}}

关于symfony - 模板渲染过程中抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37379526/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com