【问题标题】:PHP / MYSQL - Best way to store data for a page layout and content in a CMSPHP / MYSQL - 在 CMS 中存储页面布局和内容数据的最佳方式
【发布时间】:2013-11-02 12:31:50
【问题描述】:

我正在开发一个简单但灵活的内容管理器,对于页面管理,我想让用户有机会通过在页面中拖动内容来组织布局,能够将内容行除以 2 或三,就像一张桌子。

下图可以说明我的想法:

用户可以将布局设置为左侧为静态图像,右侧为文本,在底部,他可以放置一个显示缩略图的图片库。

现在,我的问题是关于如何在 Mysql 中存储和加载数据...

我有两个选择:

1) 布局的序列化数据:

在页面表中,我可以有一个字段来存储此布局的序列化数据,然后,我只需要反序列化并使用此数组进行循环以组合内容。

数组是这样的:

// Rows / divisions ...
$array[0]['q'] = 2;
$array[1]['q'] = 1;

// The content
$array[0]['c'][0]['t'] = 3;     // 't' = type (3 = image)
$array[0]['c'][0]['i'] = 124;   // 'i' = id to search for this data
$array[0]['c'][1]['t'] = 1;     // 't' = type (1 = text)
$array[0]['c'][1]['i'] = 2;     // Referencia ao ID do conteudo
$array[1]['c'][0]['t'] = 4;     // 't' = type (4 = image gallery)
$array[1]['c'][0]['i'] = 9;     // Referencia ao ID do conteudo

以及存储在数据库中的序列化数据:

a:2:{i:0;a:2:{s:1:"q";i:2;s:1:"c";a:2:{i:0;a:2:{s:1:"t";i:3;s:1:"i";i:124;}i:1;a:2:{s:1:"t";i:1;s:1:"i";i:2;}}}i:1;a:2:{s:1:"q";i:1;s:1:"c";a:1:{i:0;a:2:{s:1:"t";i:4;s:1:"i";i:9;}}}}

或者我有其他选择:

2) 全部在数据库中:

在这里我可以创建一个表格来存储页面的所有“组件”链接,包括行/分区,然后我可以进行查询来组合内容;

表格应该是这样的:

id -> component id
id_page -> page´s id
type -> component type, and 0 == row
value -> id reference to content or quantity of divisions for the rows

数据会这样存储:

id / id_page / type / value
1 / 1 / 0 / 2 --> the first row divided in two
2 / 1 / 3 / 124 --> the image
3 / 1 / 1 / 2 --> the text
4 / 1 / 4 / 9 --> the image gallery

那么,你们会使用哪些选项来获得更好的绩效或更好的管理?这是制作我想要的东西的最佳方式吗?

对不起,如果我在某些方面不清楚。

非常感谢!

【问题讨论】:

    标签: php mysql performance content-management-system organization


    【解决方案1】:

    当您需要以前为某个元素保存的数据或配置时,最好将其非规范化到键值表中。

    element_id | serialized_data
    

    在性能方面,您只需要为 element_id 编制索引,并且每个 element_id 都会有 1 行命中,其中包含数据。

    【讨论】:

      猜你喜欢
      • 2012-07-27
      • 2012-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多