简体   繁体   English

自定义 Symfony 与实体捆绑

[英]Custom Symfony Bundle with Entities

I want to create a symfony bundle for a Role and Right system.我想为角色和权限系统创建一个 symfony 捆绑包。 I want to provide the user of this bundle with the necessary entities.我想为这个包的用户提供必要的实体。 I want to make it so that the user can still edit the entities.我想这样做,以便用户仍然可以编辑实体。 In other words, I want to move the entities from my bundle to the symfony project of the end user (src/Entity/).换句话说,我想将实体从我的包移动到最终用户的 symfony 项目 (src/Entity/)。 This way the end user can still customize the entities should he or she wish to do so.这样,如果最终用户希望这样做,最终用户仍然可以自定义实体。

I have been Googling a fair bit and the only things I found were symfony recipes and a custom symfony-maker class.我一直在谷歌上搜索,我发现的唯一东西是 symfony 食谱和定制的 symfony 制造商 class。 The problem with recipes are that you have to get approved by symfony.食谱的问题是你必须得到 symfony 的批准。 The custom maker bundle on the otherhand confuses me to no end.另一方面,定制制造商捆绑让我无所适从。

Do any of you have some tips?你们有什么建议吗? This is my first time that I am making a Symfony bundle and there are not that many great resources.这是我第一次制作 Symfony 捆绑包,并且没有那么多好的资源。

As i told you, you can extend Doctrine Entities ( https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/inheritance-mapping.html )正如我告诉你的,你可以扩展 Doctrine 实体( https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/inheritance-mapping.ZFC336FDC70D22269D25A2583

/** @ORM\MappedSuperclass */
class A {
   /** @ORM\Column(type="integer") */
   protected $id;

   /** @ORM\Column(type="string") */
   protected $title;
}
/** @ORM\Entity */
class B extends A {
   /** @ORM\Column(type="string") */
   protected $author;
}

So you do not have to define all properties.因此,您不必定义所有属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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