FOSUserBundleを拡張してうまく動作するUserBundleを持っています。しかし今、私はdifférentsプロパティを持つ複数のユーザーエンティティを作成したい。 しかし、私はこのように私のメインのUserエンティティを拡張し、私のユーザーenttityを作成するときに問題がある:FOSUserBundleのユーザーエンティティはどのように拡張されますか?
class User extends BaseUser
{
protected $id;
// The main user class who extends FOSUser entity
}
class UserB extends User
{
//
}
私はこれを行うと、私はエラーが持っている: `
Access level to MyApp\UserBundle\Entity\UserB::$id must be protected (as in class MyApp\UserBundle\Entity\User).
そして私を私は、この持っている私のユーザーBのエンティティで保護されたIDを作成します。
PHP Fatal error: Cannot redeclare MyApp\UserBundle\Entity\UserB::$id.
を、完了するために、私はあまりDoctrineのエラーを返す私のUserエンティティにIDを削除することはできません。
[Doctrine\ORM\Mapping\MappingException]
No identifier/primary key specified for Entity 'MTS\UserBundle\Entity\User'. Every Entity must have an identifier/primary key.
誰かが私を助けることができますか?
EDIT:問題を解決しました。私のコード:
/**
* MTS\UserBundle\Entity\User
*
* @ORM\Entity
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(name="type", type="string")
* @ORM\DiscriminatorMap({"userfb" = "UserFB"})
*/
abstract class User extends BaseUser
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string $type
*/
private $type;
}
/**
* @ORM\Table()
* @ORM\Entity()
*/
class UserB extends User
{
// My variables
}
ありがとうを
は、私は自分の作業コードからこれを除去することによって、エラーメッセージ「識別子/主キーを持っている必要がありますすべてのエンティティ」あなたを複製することができましたあなたの答えです。最終的に、私の問題は悪い継承に起因します。 自分のコードの編集を見てください。 – Naelyth