我有三个php类Ville.php,User.php,Gouvernorat.php和他们之间的关系是User have One ville所以我在我的班级中有一个属性ville用户和ville属于一个Gouvernorat所以我有一个属性Gouvernorat也属于我的班级,所以这里是我的RegistrationFormType:
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
// add your custom field
$builder->add('name');
//$builder->add('prenom');
//$builder->add('telephone');
$builder->add('ville','entity', array(
'class' => 'Smart\UserBundle\Entity\Ville',
'query_builder' => function(EntityRepository $er) {
return $er->createQueryBuilder('u')
->orderBy('u.nom', 'ASC');
},
'property' => 'nom',
'multiple' => false,
'required' => true));
$builder->add('Gouvernorat','entity', array(
'class' => 'Smart\UserBundle\Entity\Gouvernorat',
'query_builder' => function(EntityRepository $er) {
return $er->createQueryBuilder('u')
->orderBy('u.name', 'ASC');
},
'property' => 'name',
'multiple' => false,
'required' => true));
}
问题是,当我添加Gouvernorat生成我的组合框时,它告诉我用户天堂属性Gouvernorat:
An exception has been thrown during the rendering of a template ("Neither the property
Gouvernorat" nor one of the methods "getGouvernorat()", "isGouvernorat()",
"hasGouvernorat()", "__get()" exist and have public access in class
"Smart\UserBundle\Entity\User".") in ::layout.html.twig at line 101.
如果我将一个attribut gouverorat添加到我的班级用户并将其设置为getter和setter它可以工作但不练习因为只有我的班级ville具有属性governorat。
我该如何解决?
感谢。