简体   繁体   中英

Login with Single Table Inheritance

I have an entity Account and two tables inherited with Single Table Inheritance from it: Client and Administrator .

I have a login form that uses the Account table. Once the user is logged in, I get the information like this:

    $account = $this->em->getRepository ( 'Entities\Account' )
   ->findOneByEmail ( $email ) );

I get the account with no problem, but the issue is: how do I find out if the user is a Client or an Administrator? I know I can do get_class and see which class it's using, but I don't think that's the correct way. Any help? Thanks!

if you do not want to use get_class you would do something like this

class Client extends Account
{
    protected $discr  = 'client';
    ...
}

class Administrator extends Account
{
    protected $discr  = 'administrator';
    ...
}

a field in the object (not in the database)

and create getType() method in Acount class

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM