php - 如何将视图模板存储到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']); ?>
或类似的东西。
这是正确的方法还是有其他更聪明的方法可以做到这一点?
我希望我能把我的问题说清楚。
解决方案
推荐阅读
- swift - 没有 NavigationLink 的 SwiftUI 列表披露指示器
- python - 当两组点包含噪声时如何对齐两组点(平移+旋转)?
- css - 如何在更改屏幕尺寸时完美对齐自定义 CSS 图像而不会遇到问题?
- python - Python:识别列中的值更改并计算/标记特定值的每组
- python - 如何在 Glitch 中使用 Python 中的环境变量
- flutter - Flutter 在 AppBar 和 body 之间添加 Space
- php - 将产品数据选项卡更改为手风琴并在添加到购物车按钮后移动它们
- flutter - Flutter Web 中的 NTLM 身份验证。选项?
- flutter - Flutter:不同平台的不同依赖版本?
- flutter - Flutter 导航抽屉和有状态小部件的“删除”状态