在树枝中调用数组

时间:2015-07-06 23:31:37

标签: php symfony twig

无法将实体资源中的主键(id)数组返回到questionanswer twig。

QuestionAnswer模板:

 {% 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.getResources is empty %}
                <p> </p>
            {% else %}
                <a href="{{ path('resource_show', { 'id': entity.id }) }}">Yes</a>
            {% endif %}
        </td>

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 个答案:

没有答案