【发布时间】:2011-06-04 22:22:33
【问题描述】:
我希望构建一个类似于 Drupal 的 CCK 的 Codeigniter 库,尽管它是一个极其简化的版本。我想知道哪种数据库结构最适合实现我的最终目标,最好用以下用例来描述:
界面:
现有内容类型:
- 页面[编辑类型] [列出所有] [添加新页面]
- 评级 [编辑类型] [列出所有] [添加新评级]
- DVD 电影 [编辑类型] [列出所有] [添加新的 DVD 电影]
[创建新的内容类型]
网络开发者点击【创建新的内容类型】:
表单:新的内容类型
输入标题:[_访客评论____________强>]
添加字段:
- 字段名称:[_名称__________]
- 字段类型:[文本(](带基本选项的下拉菜单)
- 必填值:[x]
- [添加字段]
[保存内容类型]
Web 开发人员添加了几个字段:
表单:新的内容类型
输入标题:[_访客评论____________强>]
当前字段:
- 姓名 |文本(
- 电子邮件 |文本(
- 内容 |文本(
- ForPage |页 |必填
添加字段:
- 字段名称:[_____________ ]
- 字段类型:[ -choose below- ]i>
- 必填值:[ ]i>
- [添加字段]
[保存内容类型]
网页开发者保存内容类型,系统创建……嗯,究竟是什么?
想法 1: 我可以很容易地让它创建一个带有相应字段的新数据库表(这基本上会形成一个非常基本的 phpmyadmin 系统)——但这是否明智?这不会在数据库中乱扔很多表吗?
想法 2: 或者我可以创建一个“数据库内的数据库”,类似于:
table ContentType (e.g. "Book")
-- id
-- title
table CustomField (e.g. "Author Name")
-- id
-- ContentTypeID (linking the "Author Name" field to the "Book" type)
-- valueType (linking the field to the correct db table of values)
table DBRecord (e.g. "Lord Of The Rings vol.1")
-- id
-- ContentTypeID (linking the LotR record to the "Book" type)
table ValueText128 (e.g. "J.R.R. Tolkien")
-- id
-- DBRecordID (linking the value to the LotR record)
-- CustomFieldID (linking the Tolkien value to the "Author Name" field)
-- value : char(128)
table ValueSmallInt (e.g. "1954")
-- id
-- DBRecordID (linking the value to the LotR record)
-- CustomFieldID (linking the "1954" value to the "Published Year" field)
-- value : smallInt
...and so on, with a table for each of the datatypes
这可能可行,但我怀疑它在实践中可能效率极低,因为整个系统中每种类型的每个项目的每个整数值最终都会出现在同一个大表中 - 每个字符都相同( 128) 价值等。
那么 - 你怎么看? CCK是如何做到的?什么最有效?
【问题讨论】:
标签: php database orm content-management-system cck