Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 623 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
FOSUserBundle properties in registration form from another entity

#1
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][1], 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,







[1]:

[To see links please register here]

Reply

#2
Semantically speaking, a `User` doesn'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:

namespace Acme\Bundle\AcmeBundle\Entity;

use FOS\UserBundle\Entity\User;

class Company extends User
{
// Your company related fields and related getters/setters go here.
}
Then override the user class from your configuration (e.g in `app/config/config.yml`):

fos_user:
user_class: Acme\Bundle\AcmeBundle\Entity\Company
Now the `UserBundle` knows which class to use as the `User`. After setting up your custom class you can override the `RegistrationFormType` to 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][1] and then embed your `Company` entity to `RegistrationFormType` by following the docs about [embedding a single object][2] to a form.

Reference:

[To see links please register here]



[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through