我正在开发一个简单但灵活的内容管理器,对于页面管理,我想让用户有机会通过在页面中拖动内容来组织布局,能够将内容行分成两行或三,就像一张 table 。
下图可以说明我的想法:
用户可以制作一个布局,在左边有一个静态图像,在右边有一个文本,在底部,他可以放置一个显示缩略图的图库。
现在,我的问题是关于如何在 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
那么,你们会使用哪些选项来获得更好的性能或更好的管理?这是制作我想要的东西的最佳方式吗?
抱歉,如果我在某些方面不清楚。
非常感谢!
最佳答案
当您需要以前为某个元素保存的数据或配置时,最好在键值表中对其进行非规范化。
element_id | serialized_data
在性能方面,您只需要为 element_id 建立索引,并且每个 element_id 都会命中 1 行,其中包含数据。
关于PHP/MYSQL - 在 CMS 中存储页面布局和内容数据的最佳方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19555118/