Hy guys,
I decided to use FOSUserBundle for handling user authentication in my application.
In my application, companies can register their details (name, address, etc).
So I decided to create an entity called Company to hold the company related data and an entity called User to keep the user data from FOSUserBundle separately.
I started to override the default registration form as it is described in the documentation Overriding Default FOSUserBundle Forms, but the problem is that I can’t add my fields from Company to the form, it always try to access from the User entity (propably because that one is related to FOSUserBundle).
Is there any way to put the Company entity fields in the FOSUser registration form?
I don’t want to mess up the data model by using the Company as the base entity for FOSUser and adding to it all the fields (username, email, password, etc).
Best regards,
Semantically speaking, a
Userdoesn’t have to be a person, so I see no reason for a company being your application’s user. I also see no reason for having two separate tables in your database.I would create a separate Company class, which extends the user class:
Then override the user class from your configuration (e.g in
app/config/config.yml):Now the
UserBundleknows which class to use as theUser. After setting up your custom class you can override theRegistrationFormTypeto include your custom fields.If, however, you still wish to use two separate entities in your application, I suggest you connect them via a One-To-One relationship and then embed your
Companyentity toRegistrationFormTypeby following the docs about embedding a single object to a form.Reference: https://github.com/FriendsOfSymfony/FOSUserBundle/blob/1.2.0/Resources/doc/overriding_forms.md