我正在尝试在问题答案 Twig 页面中使用包含标签来包含资源 Twig 页面的实体(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 中。
问题答案实体:
/**
* @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;
最佳答案
该方法在您的对象中名为 getResources
,但您在模板中使用 getResource
(注意单数)
关于php - 在 TWIG 中包含标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31331895/