简体   繁体   English

PHP / MYSQL - 在CMS中存储页面布局和内容数据的最佳方式

[英]PHP / MYSQL - Best way to store data for a page layout and content in a CMS

I´m developing a simple, but flexible content manager, and for the pages management i want to give the user the opportunity to organize the layout by dragging contents in the page, being able to make rows of content divided by two or three, just like a table. 我正在开发一个简单但灵活的内容管理器,对于页面管理,我想让用户有机会通过拖动页面中的内容来组织布局,能够将内容行分成两行或三行,像一张桌子。

The following image can illustrate what i have in mind: 以下图片可以说明我的想法:

在此输入图像描述

The user can make a layout to have an static image in the left, and a text on the right, and at the bottom, he can place an image gallery showing the thumbnails. 用户可以使布局在左侧具有静态图像,在右侧具有文本,并且在底部,他可以放置显示缩略图的图像库。

Now, my question is about how to store and load the data in Mysql... 现在,我的问题是如何在Mysql中存储和加载数据...

I have two Options: 我有两个选项:

1) With serialized data for the layout: 1)使用布局的序列化数据:

In the page´s table i can have a field that will store a serialized data for this layout, and then, i just need to unserialize and make a loop with this array to assemble the content. 在页面表中,我可以有一个字段,用于存储此布局的序列化数据,然后,我只需要反序列化并使用此数组进行循环以组合内容。

The Array would be like that: 数组将是这样的:

// 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

and the serialized data to store in DB: 和要存储在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;}}}}

Or i have other option: 或者我有其他选择:

2) All in database: 2)全部在数据库中:

Here i can make a table to store all the "component" links for the page, including the rows/divisions and than i can make a query to assemble the content; 在这里,我可以创建一个表来存储页面的所有“组件”链接,包括行/分区,然后我可以进行查询来组合内容;

The table would be something like that: 该表将是这样的:

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

And the data would be stored like that: 数据将存储如下:

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

So, what options do you guys would use to have a better performance or better management? 那么,你们会用什么方法来获得更好的性能或更好的管理? Is this the best way to make what i want? 这是制作我想要的最佳方式吗?

Sorry if i was not clear in some point. 对不起,如果我在某些方面不清楚。

Thank you so much! 非常感谢!

When you need data or configurations previously saved for some element, its better to have it denormalized in a key value table. 当您需要先前为某个元素保存的数据或配置时,最好在键值表中对其进行非规范化处理。

element_id | serialized_data

performance wise you only need to index element_id and you will have a 1row hit for each element_id with the data on it. 性能方面你只需要索引element_id,每个element_id都会有1row命中数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM