特征 - 属性与父类冲突

时间:2014-06-11 08:42:59

标签: php symfony inheritance conflict traits

我有这个Zgh\FEBundle\Entity\User课,它扩展了FOS\UserBundle\Model\User

use FOS\UserBundle\Model\User as BaseUser;

class User extends BaseUser implements ParticipantInterface
{
    use BasicInfo;
    // ..
}

BaseUser课程:

abstract class User implements UserInterface, GroupableInterface
{
    protected $id;
    // ..
}

BaseInfo特质:

trait BasicInfo
{
    /**
     * @ORM\Column(type="string", length=255)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="NONE")
     */
    protected $id;

    // ..
}

但是当我运行我的代码时,我得到了这个错误:

  

严格的标准:FOS \ UserBundle \ Model \ User和   Zgh \ FEBundle \ Model \ Partial \ BasicInfo定义了相同的属性($ id)   Zgh \ FEBundle \ Entity \ User的组成。这可能是   不兼容,请考虑在特征中使用访问器方法。

我正在使用Symfony框架。

无论如何要解决trait和父类对象之间关于此属性的冲突吗?

1 个答案:

答案 0 :(得分:2)

不,现在还不能使用特征重写映射属性。

此外,一种可能的替代方法是使用多个抽象实体类,并根据您的需要扩展您的子实体。

/**
* @ORM\Entity
*/
class Child extends AbstractStrategyNoneEntity 
{
    // Inherited mapping
}

并在您的子实体中扩展其中一个。

    Dim Start As New ProcessStartInfo
    Start.FileName = "iexplore.exe"
    Start.Arguments = "-private  " & "http://www.google.com"
    Process.Start(Start)

希望这能回答你的问题。

相关问题