如何创建抽象 class,并使用 Doctrine2 扩展它?
How to create abstract class, and extend it using Doctrine2?
我想创建一个名为 Content
的摘要 class。有两种实现方式:TextContent
和VideoContent
abstract class Content {
/** @Id @Column(type="integer") @GeneratedValue **/
private $id;
/** @Column(type="string") **/
private $title;
/** getters and setters... **/
}
以及实现:
class VideoContent extends Content {
/** @Column(type="string") **/
private $source;
/** @Column(type="string") **/
private $format;
/** getters and setters... **/
}
class TextContent extends Content {
/** @Column(type="string") **/
private $text_data;
/** getters and setters... **/
}
内容必须是抽象的,因为内容不能只是内容。它是视频或文本。在 Doctrine2 中怎么可能?这将如何在 MySQL 数据库中表示?
也许这能帮到你
您必须创建一个带有鉴别器列的 table。
我想创建一个名为 Content
的摘要 class。有两种实现方式:TextContent
和VideoContent
abstract class Content {
/** @Id @Column(type="integer") @GeneratedValue **/
private $id;
/** @Column(type="string") **/
private $title;
/** getters and setters... **/
}
以及实现:
class VideoContent extends Content {
/** @Column(type="string") **/
private $source;
/** @Column(type="string") **/
private $format;
/** getters and setters... **/
}
class TextContent extends Content {
/** @Column(type="string") **/
private $text_data;
/** getters and setters... **/
}
内容必须是抽象的,因为内容不能只是内容。它是视频或文本。在 Doctrine2 中怎么可能?这将如何在 MySQL 数据库中表示?
也许这能帮到你
您必须创建一个带有鉴别器列的 table。