Symfony3 FOSuserbundle注册表形成一对一实体

时间:2017-12-06 18:26:34

标签: php symfony fosuserbundle

我需要在我的symfony基础应用程序中使用4种类型的用户,其中一种是超级用户,可以只是典型的fosuserbundle用户,但需要管理员可以添加3种不同类型的用户。所以我为一种类型的用户做了一个新的Client类,它有1:1的实体和我的基本用户类

class Client{
my client class fields
...
   /**
   * @ORM\OneToOne(targetEntity="AppBundle\Entity\User")
   * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
   */
  private $user;
...
}

我的用户类

class User extends BaseUser
{......}

问题是如何为此注册表格?请帮帮我

现在我有了这个UserType表格

class UserType extends AbstractType
{
   public function buildForm(FormBuilderInterface $builder, array $options)
   {
       parent::buildForm($builder, $options);
   }

   public function configureOptions(OptionsResolver $resolver)
   {
       $resolver->setDefaults(array(
          'data_class' => User::class,
       ));
   }

   public function getParent()
   {
       return 'FOS\UserBundle\Form\Type\RegistrationFormType';
   }

   public function getBlockPrefix()
   {
       return 'app_user_registration';
   }
}

我的clientForm类

class ClientForm extends AbstractType
{
   public function buildForm(FormBuilderInterface $builder, array $options)
   {
       $builder
           ->add('name', TextType::class)
           ->add('address', TextareaType::class)
           ->add('phone', TextType::class)
           ->add('deliveryAddress', TextareaType::class)
           ->add('user', UserType::class);
   }

   public function getParent()
   {
       return 'FOS\UserBundle\Form\Type\RegistrationFormType';
   }

   public function getBlockPrefix()
   {
       return 'app_user_registration';
   }

   public function configureOptions(OptionsResolver $resolver)
   {
       $resolver->setDefaults([
           'data_class' => Client::class,
       ]);
   }
}

但这给了我一个错误

Neither the property "email" nor one of the methods "getEmail()", "email()", "isEmail()", "hasEmail()", "__get()" exist and have public access in class "AppBundle\Entity\Client".

1 个答案:

答案 0 :(得分:0)

Oki,早些时候我尝试了很多不同的方法来做到这一点,我只是从我的ClientForm类中删除了getParent和getBlockPrefix,所有看起来都很好:)