重写原则实体 [英] Overriding Doctrine Entities

查看:121
本文介绍了重写原则实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Doctrine 2实体在Symfony2上创建一个应用程序。我的问题是,我应该有一个主要的应用程序,其中包含主要使用的功能和其他应用程序,将需要扩展它。例如我有一个UserInterface,还有一个在主应用程序中实现UserInterface的用户。所有其他应用程序应该能够使用此用户,但是如果一个应用程序需要向此用户添加更多属性,则他可以覆盖用户类而不更改其名称或函数调用。我已经通过@MappedSuperClass阅读了关于教义的文档(不能解决我的问题),并在另一个问题中看到一个实现,改变了驱动程序的实现,但我希望有另一个解决方案。

I'm trying to create an application on Symfony2 with Doctrine 2 entities. My problem is that I should have a main application which contains the mainly used functions and other applications which are gonna extend it on need. For example i have a UserInterface and also a User which implements UserInterface in the main App. All the other applications should be able to use this User, but in case one of the apps needs to add more properties to this User he is able to override the user class without changing it s name or the functions call. I already read the doc about doctrine with the @MappedSuperClass(doesn t solve my problem) and saw an implementation in an other question with changing the driver implementation but I hope there s another solution for this. Thanxs to anybody who can help.

推荐答案

我想你正在寻找的是Bundle继承:
http://symfony.com/doc/2.0/cookbook/bundles/inheritance.html

I think what you are looking for is Bundle Inheritance: http://symfony.com/doc/2.0/cookbook/bundles/inheritance.html

如果将Bundle B定义为A的父级,则只要Bundle使用相同的命名空间/文件夹,Bundle A中的每个资源都将覆盖Bundle B中的资源。

If you define Bundle B as Parent of A, every Resource in Bundle A will overwrite the Resource in Bundle B as long as both Bundles use the same Namespaces / Folders.

几天前我用它来覆盖FOSUserBundle的控制器。

I used that a few days ago to overwrite Controllers of FOSUserBundle.

这篇关于重写原则实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆