[英]PHP / MYSQL - Best way to store data for a page layout and content in a CMS
我正在开发一个简单但灵活的内容管理器,对于页面管理,我想让用户有机会通过拖动页面中的内容来组织布局,能够将内容行分成两行或三行,像一张桌子。
以下图片可以说明我的想法:
用户可以使布局在左侧具有静态图像,在右侧具有文本,并且在底部,他可以放置显示缩略图的图像库。
现在,我的问题是如何在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
和要存储在DB中的序列化数据:
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都会有1row命中数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.