0

I've been working with Symfony2 for a few weeks, and loving it.

However, I am a bit confused with an aspect. Say I have two bundles, which each have a "User" entity, which stores information about that user.

However, I want to be able to do actual authentication with whatever authentication the site admin chooses (even if it isn't one of the user entities from my bundles).

What are the best practices to organize these Entities and link them all up, while remaining flexible with the actual authentication.

Thanks.


UPDATE: Here is a clarification.

Imagine I have two bundles: forum and wiki.

Now, for the users, there is a lot of different data that those two systems would want to store. So, each would have some place to store them (like two different tables). However, neither of them store authentication information, only other information.

The idea would be that whichever authentication method was used, they would be able to get that token then determine which user data they should use in their own bundles. That way, the bundles would be able to work independently of each other as well as independently of the authentication method.

samanime
  • 25,408
  • 15
  • 90
  • 139
  • Are you saying there's actually multiple user tables in the db, or just that you're using multiple Entity classes with something like inheritance with a discriminator column? – Peter Bailey Jun 12 '12 at 17:39
  • It'd equate to multiple user tables, kind of. Check my edit for clarification. – samanime Jun 13 '12 at 22:37

1 Answers1

0

I think you want to avoid having multiple User entities. To quickly integrate some best practices into your application, take a look at the FOSUserBundle. This will give you roughly 80% of the functionality you need to allow users to register, login, etc. Create your own UserBundle within your application that extends FOSUserBundle. For example, your User entity would probably look like this:

use FOS\UserBundle\Entity\User as BaseUser;

/**
 * Extend the FOSUserBundle base User class.
 * @ORM\Entity
 * @ORM\Table(name="user")
 */
class User extends BaseUser {
    ...
}

Reference this extended User entity (YourApp\UserBundle\Entity\User) as the canonical User entity throughout all other bundles in your project.

nurikabe
  • 3,802
  • 2
  • 31
  • 39
  • That could work, but my goal (which the more I read my be impossible) is to allow the site admin to use ANY authentication method, even something like an in-memory one. Though, it seems that is impossible without having an artificial string foreign key, which gets very ugly very fast. I'll check that bundle out though. Thanks. – samanime Jun 13 '12 at 21:56