0

Hello I have a technical question on how to implement multiple user types (not using FOS). I'll explain what I'm willing to do, I'd like some feedback on what can be done better or a suggestion on how to do it.

I'll have 4 entities

  • user
  • amateur
  • profesional
  • organisation

The default one that is implemented right now is user. To get things out of the way I'll user a second user provider for organisation as it will not be related to the previous ones.

I'm wondering how to do the User, Amateur, Profesional accounts.

They share most of the basic fields just have additional information to them. Most of them have the same permissions. Whats the best way to do It?

1) Adding a one to one extra entity to the User Class I'll add a one to one AmateurInformation and ProInformation to the main User class. And determine the account type by a single accountType field. 2) Extending the Class with a child class? I don't even know that something like this is possible. Also I'd like to make requests to the Repo that will return all User types.

Again I'm looking for suggestions on what to look into and how I can do this. I want to improve my knowledge while I'm at it :)

1 Answer 1

1

In my view two suggested solutions are viable (introducing a type field or using inheritance), really depends on your situation.

I would avoid using multiple independent classes, it will just complicate it.

If the relation to other database entries does not justify, it is not required to create separate classes, you can use the type field and maybe introduce specific roles (see getRoles() in UserInterface) for your different users.

If your user classes will have access to different things (relations to other entities), I would consider using a Single Table Inheritance with doctrine. With this solution you still can use one UserProvider and in code you can check the user object, and also, you can use custom roles to give permissions:

if ($user instanceOf Amateur)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.