首页 > 解决方案 > 如何将视图模板存储到mysql数据库中

问题描述

我想创建视图模板文件(具有不同页面结构和 css 的现成页面模板)并将其保存到 mysql 数据库中。

每个模板文件都会呈现相同的记录,只是布局会有所不同。

管理员可以在配置时从数据库中选择必要的可用模板,并且数据将在常规用户界面上呈现到该模板中。

我曾想过将文件创建为:

views/templates/template1.php
views/templates/template2.php
views/templates/template3.php...

在我的项目视图目录中,并将这些模板名称手动插入到数据库中:

template_id  |  template_file_name  |  status
---------------------------------------------
1            |  template1.php       |  1
2            |  template2.php       |  1
3            |  template3.php       |  1
4            |  template4.php       |  0

也就是说,对于问答测试或其他内容,管理员可以从这些可用模板中的任何一个中进行选择。

当用户加载特定的问题/答案集时,q/a 记录将被加载到该模板中:

question_answer.php:

<?php include($row['template_file_name']); ?>

或类似的东西。

这是正确的方法还是有其他更聪明的方法可以做到这一点?

我希望我能把我的问题说清楚。

标签: phphtmlmysqltemplatesview

解决方案


推荐阅读