2016-06-08 30 views
0

FosUserBundle - >重寫ProfileTypeForm.phpSymfony3實體型不起作用

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()存在並在012類公共訪問。

Entity\LocationProvince是使用控制檯和數據庫更新創建的,架構已創建。

Province刪除時工作正常。

回答

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'); 
    } 
)); 

看看是否能工程...

+0

哇,我想這將是這麼簡單,謝謝 –

+0

很高興它的工作! –