Doctrine: extending entity class(Doctrine:扩展实体类)
问题描述
我想扩展 EntityBase 类,如何在 Doctrine 2.1 中做到这一点?我的研究表明,每当有人遇到这样做的问题时,他就会切换到 Doctrine 1.2 :)n 我使用的是 yaml 配置
I would like to extend EntityBase classes, how to do this in Doctrine 2.1? My research showed that whenever someone encounters the problem with doing this he switches to Doctrine 1.2 :)n I am using yaml configuration
推荐答案
Doctrine 2.X 实体作为 POPO(Plain Old PHP Objects)工作.为了实现正确的扩展,Doctrine 强制您使用 JPA 中称为 Mapped Super Classes 的概念.这个想法很简单.每当您想要拥有一个基类并希望您的实体从中扩展时(我不是在谈论 DB 级别的继承),您需要做的就是将基类创建为 MappedSuperClass.
Doctrine 2.X Entities work as POPOs (Plain Old PHP Objects). To achieve extending correctly, Doctrine enforces you to use a concept from JPA called Mapped Super Classes. The idea is pretty simple. Whenever you want to have a base class and want your entities to extend from it (I'm not talking about inheritance at DB level), all you need to do is create your Base class as a MappedSuperClass.
这是一个例子:http://www.doctrine-project.org/docs/orm/2.1/en/reference/inheritance-mapping.html#mapped-superclasses
谢谢
这篇关于Doctrine:扩展实体类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Doctrine:扩展实体类
基础教程推荐
- 如何替换eregi() 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
