Overriding Doctrine Entities

2019-07-19 12:43发布

问题:

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.

回答1:

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

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.

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