How extends User entity of FOSUserBundle?
I have my UserBundle who extends the FOSUserBundle and works fine. But now, I want create multiple users entities with différents properties. But the problem is when I create my user enttity who extends my main User entity like this :
class User extends BaseUser
{
protected $id;
// The main user class who extends FOSUser entity
}
class UserB extends User
{
//
}
When I do this, I've got an error : `
Access level to MyAppUserBundleEntityUserB::$id must be protected (as in class MyAppUserBundleEntityUser).
And when I create a protected id in my UserB entity I have this:
PHP Fatal error: Cannot redeclare MyAppUserBundleEntityUserB::$id.
And to finish, I can't delete the id in my User entity less return a Doctrine error :
[DoctrineORMMappingMappingException]
No identifier/primary key specified for Entity 'MTSUserBundleEntityUser'. Every Entity must have an identifier/primary key.
Someone can help me ?
EDIT : Problem solved. My code :
/**
* MTSUserBundleEntityUser
*
* @ORMEntity
* @ORMInheritanceType("SINGLE_TABLE")
* @ORMDiscriminatorColumn(name="type", type="string")
* @ORMDiscriminatorMap({"userfb" = "UserFB"})
*/
abstract class User extends BaseUser
{
/**
* @var integer $id
*
* @ORMColumn(name="id", type="integer")
* @ORMId
* @ORMGeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string $type
*/
private $type;
}
/**
* @ORMTable()
* @ORMEntity()
*/
class UserB extends User
{
// My variables
}
You problem appears to be the lack of annotation.
I was able to replicate your 'Every Entity must have an identifier/primary key' error message by removing this from my working code:
/**
* @ORMId
* @ORMColumn(type="integer")
* @ORMGeneratedValue(strategy="AUTO")
*/
The works for me:
/**
* @ORMEntity
* @ORMTable(name="fos_user")
*/
class User extends BaseUser
{
/**
* @ORMId
* @ORMColumn(type="integer")
* @ORMGeneratedValue(strategy="AUTO")
*/
protected $id;
public function __construct()
{
parent::__construct();
// your own logic
}
}
链接地址: http://www.djcxy.com/p/69376.html
上一篇: PHP特质会是一个很好的解决方案