我正在尝试在questionanswer Twig页面中使用include标签来包含资源树枝页面的实体(queId)但是我收到错误:
questionanswer.html.twig:
{% for entity in entities %}
<tr>
<td><a href="{{ path('questionanswer_show', { 'id': entity.id }) }}">{{ entity.id }}</a></td>
<td>{{ entity.question }}</td>
<td>{{ entity.answer }}</td>
<td>
{% if entity.getResource is empty %}
<p> </p>
{% else %}
<a href="{% include 'SymfonySymfonyBundle:resource:index.html.twig' with { 'id': entity.queId } %}">Yes</a>
{% endif %}
</td>
无法将外键(queId)从资源实体返回到questionanswer twig。
questionAnswer实体:
/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="resource", mappedBy="queId")
*/
private $resources;
/**
* Get resources
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getResources() {
return $this->resources->toArray();
资源实体:
/**
* @var integer
* @ORM\ManyToOne(targetEntity="questionanswer", inversedBy="resources")
* @ORM\JoinColumn(name="que_id", referencedColumnName="id")
*/
private $queId;
答案 0 :(得分:2)
该方法在您的对象中命名为getResources
,但您在模板中使用getResource
(注意单数)