FosUserBundle - >覆盖ProfileTypeForm.php
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->remove('username');
$builder->add('Profile', MyProfileTypeForm::class, array(
'mapped' => true,
'label' => false,
'required' => true,
'translation_domain' => 'FOSUserBundle',
));
}
MyProfileTypeForm.php文件:
public function buildForm(FormBuilderInterface $builder, array $options)
{
....
$builder
->add('firstname', TextType::class, array(
'label' => 'form.profile.firstname',
'constraints' => array(
new NotBlank(),
new Length(array('min' => 3))
)
))
->add('country', CountryType::class, array(
'label' => 'form.profile.country',
'preferred_choices' => array(
'EN'
)
))
->add('province', EntityType::class, array(
'class' => 'Panel\UserBundle\Entity\LocationProvince',
'choice_label' => 'Province',
'query_builder' => function (EntityRepository $em){
return $em->createQueryBuilder('l')
->orderBy('l.name');
}
));
}
错误代码:
属性'省'或方法getProvince()
,province()
,isProvince()
,hasProvince()
,__get()
都不存在,并且在课堂上具有公共访问权限Panel\UserBundle\Entity\LocationProvince
。
Entity\LocationProvince
是使用控制台和数据库更新创建的,已创建模式。
Province
在删除后工作正常。
答案 0 :(得分:0)
改变这个:
->add('province', EntityType::class, array(
'class' => 'AppBundle:LocationProvince',
'choice_label' => 'Province',
'query_builder' => function (EntityRepository $em){
return $em->createQueryBuilder('l')
->orderBy('l.name','ASC');
}
));
看看是否有效......