I have three relevant entities in my application with a oneToMany reation: one "Aufwand" belongs to one "Aufgabe", wich belongs to one "Version". At some point in the controller, I write:
在我的申请中,我有三个相关的实体:一个“Aufwand”属于一个“Aufgabe”,它属于一个“版本”。在控制器的某个时刻,我写道:
$Aufwand['version'] = $Aufwand->getAufgabe()->getVersion();
and pass that to the Twig template with:
并将其传递给Twig模板:
return $this->render('XXX:Aufwand:index.html.twig', array('Aufwand' => $Aufwand));
"Version" has a String attribute "nummer" wich I try to access in my Template using
“版本”有一个字符串属性“nummer”,我尝试在我的模板中使用。
{{ Aufwand.version.nummer }}
but it prints nothing, same for all other attributes of "Version" - but I checked and Aufwand.version
alone is really an XXXXVersionProxy
- Object, as it should be. So appearantly the "Lazy-Loading" from Doctrine does not really happen.
但它没有打印任何东西,这与“版本”的所有其他属性相同——但我检查了一下,并使用了Aufwand。单独的版本实际上是一个XXXXVersionProxy -对象,它应该是这样的。因此,从教义上看来,“延迟加载”并不真的发生。
This is the Mapping information in "Version.orm.yml":
这是“版本.orm.yml”中的映射信息:
XXX\Entity\Version:
type: entity
repositoryClass: XXX\Repository\VersionRepository
table: version
id:
Projekt:
associationKey: true
nummer:
type: string
length: 20
fields:
beschreibung:
type: text
nullable: true
faktor:
type: decimal
precision: 2
scale: 1
uniqueConstraints:
version_nr_unique:
columns: nummer
oneToMany:
Aufgaben:
targetEntity: Aufgabe
mappedBy: Version
manyToOne:
Projekt:
targetEntity: Projekt
inversedBy: Versionen
joinColumn:
name: projekt_nummer
referencedColumnName: nummer
and in "Aufgabe.orm.yml":
在“Aufgabe.orm.yml”:
XXX\Entity\Aufgabe:
type: entity
repositoryClass: XXX\Repository\AufgabeRepository
table: aufgabe
id:
id:
type: integer
generator:
strategy: AUTO
fields:
name:
type: string
length: 40
beschreibung:
type: text
nullable: true
faktor:
type: decimal
precision: 2
scale: 1
soll_aufwand:
type: integer
oneToMany:
Aufwaende:
targetEntity: Aufwand
mappedBy: Aufgabe
manyToOne:
Kategorie:
targetEntity: Kategorie
inversedBy: Aufgaben
joinColumn:
name: kategorie_id
nullable: false
referencedColumnName: id
Projekt:
targetEntity: Projekt
inversedBy: Aufgaben
joinColumn:
name: projekt_nummer
referencedColumnName: nummer
nullable: true
Version:
targetEntity: Version
inversedBy: Aufgaben
joinColumn:
name: version_nummer
nullable: true
referencedColumnName: nummer
The getters and setters in "Version" and "Aufgabe" are standard "get{Attribute}()", the attributes themselves are private. I have already tried clearing the metadata-cache and dumping $Aufwand->getAufgabe()->getVersion() // also plus ->getNummer()
in the controller, everything seems to be right there. And in the Database Table the "Aufwand" has an "Aufgabe" wich has a "Version" wich should give me its "nummer" ...
“版本”和“Aufgabe”中的getter和setter是标准的“get{Attribute}()”,属性本身是私有的。我已经尝试过清除metadata-cache并转储$Aufwand->getAufgabe()->getVersion() //也添加->getNummer()在控制器中,一切似乎都在那里。在数据库表中,“Aufgabe”有一个“Aufgabe”,它有一个“版本”,它应该给我它的“nummer”……
I'm using PHP Symfony 2.0.16 with Doctrine 2 on a PostgreSQL Database, any hint where to look for an error would be much appreciated. I guess it could be in the Twig template but I have no idea what is wrong.
我在PostgreSQL数据库上使用了PHP Symfony 2.0.16和Doctrine 2,任何寻找错误的提示都将非常感谢。我想可能是在Twig模板中,但我不知道什么地方不对。
1 个解决方案
#1
0
why not just pass $Aufwand to the template and do:
为什么不直接向模板传递$Aufwand,然后做:
{{Aufwand.aufgabe.version.number}}
That should work from the view.
这应该从视图中起作用。
#1
0
why not just pass $Aufwand to the template and do:
为什么不直接向模板传递$Aufwand,然后做:
{{Aufwand.aufgabe.version.number}}
That should work from the view.
这应该从视图中起作用。