我对 Symfony2 和 Doctrine 很陌生,但我用 PHP 做了一些编程。我有两张桌子:
Quotes:
id
quote
subject
auth_id
和
QuoteAuthor:
id
authorFirstName
authorLastName
authorLastNameFirstLetter
slug
我正在运行一个查询:
"SELECT u, a FROM BetterLifeQuotesBundle:Quote u u.auth_id a WHERE a.id = 4"
在这个特定的查询中,结果只有一行(作者只有一个引号)。查询是使用 WhiteOctober pagerfanta 完成的,以便于分页。我将结果传递给树枝并显示引号
{% for data in pagerfanta.currentPageResults %}
<li>{{ data.quote }}</li>
{% endfor %}
在这种情况下,将显示 data.quote 属性。
问题是:
如何显示连接QuoteAuthor
表中的数据属性?即authFirstName, authLastName
等。
我在网上搜索,我找不到任何答案。顺便说一句 - 如果在上面的 Twig 语句中,我用它替换data.quote
它data[‘quote’]
给出了“类型的对象(带有 ArrayAccess)中的键'引用'不存在”的错误。
我需要的所有信息都在其中data
,您可以在下面的转储信息中看到:
object(BetterLife\QuotesBundle\Entity\Quote)[760]
private 'id' => int 500
private 'quote' => string 'An archaeologist is the best husband a woman can have; the
older she gets, the more interested he is in her.' (length=108)
private 'subject' => string 'Men and Women' (length=13)
private 'auth_id' =>
object(BetterLife\QuotesBundle\Entity\QuoteAuthor)[758]
private 'id' => int 4
private 'authorFirstName' => string 'Agatha' (length=6)
private 'authorLastName' => string 'Christie' (length=8)
private 'authorLastNameFirstLetter' => string 'C' (length=1)
private 'slug' => string '' (length=0)
private 'quotes' =>
object(Doctrine\ORM\PersistentCollection)[753]
private 'snapshot' =>
array (size=0)
...
private 'owner' =>
&object(BetterLife\QuotesBundle\Entity\QuoteAuthor)[758]
private 'association' =>
array (size=15)
...
private 'em' =>
object(Doctrine\ORM\EntityManager)[345]
...
private 'backRefFieldName' => string 'quote_author' (length=12)
private 'typeClass' =>
object(Doctrine\ORM\Mapping\ClassMetadata)[816]
...
private 'isDirty' => boolean false
private 'initialized' => boolean false
private 'coll' =>
object(Doctrine\Common\Collections\ArrayCollection)[769]
...