Yer*_*oon 7 php symfony doctrine-orm
在我的Symfony2应用程序中,我将大部分实体提取到一个单独的库中,我使用composer进行安装.
这个库没有依赖于Symfony2(但是依赖于Doctrine,因为我使用了注释),因为我想在其他非Symfony2项目中使用它.
该库包含一个ClientUser映射到client_users表的实体.在我的Symfony2应用程序中,我想使用相同的ClientUser实体进行身份验证.这需要我实施Symfony\Component\Security\Core\User\UserInterface.
问题是我希望同时具有"Symfony2-agnostic" 和 "Symfony-aware" ClientUser实体(两者都应该映射到同一个表).我试图从ClientUserAbstract实体扩展这两个类,但它没有用.
<?php
namespace My\Library\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\MappedSuperClass
*/
class ClientUserAbstract {
// all my fields here
}
Run Code Online (Sandbox Code Playgroud)
我的"Symfony2-agnostic"实体:
<?php
namespace My\Library\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
*/
class ClientUser extends ClientUserAbstract {
// nothing here, it's empty
}
Run Code Online (Sandbox Code Playgroud)
我的"Symfony2-aware"实体:
<?php
namespace Vendor\Bundle\MyBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Entity
*/
class ClientUser extends ClientUserAbstract implements UserInterface {
// all methods that Symfony requires because of the UserInterface here:
public function getRoles();
public function getPassword();
public function getSalt();
public function getUsername();
public function eraseCredentials();
}
Run Code Online (Sandbox Code Playgroud)
我的Symfony 2应用程序现在检测到两个指向同一个表的实体,并以异常方式失败.我要么告诉我的Symfony2应用程序"忽略"我的My\Library\Entity\ClientUser,要么我需要一种方法来扩展它.有任何想法吗?
| 归档时间: |
|
| 查看次数: |
4175 次 |
| 最近记录: |