我正在尝试构建一个网站构建器,我想手动存储插件/ portlet的HTML结构,用户可以拥有结构和他们插入的任何可编辑数据,使用控制器中的序列化存储到数据库中,现在我知道MySQL不保存html数据或者说它存储不安全,我决定将基本结构存储为JSON格式到一个单独的文件中,现在我不希望将这些JSON文件存放在我的公共文件夹目的地,我浏览了Seeder文档和教程,找到了文件的路径并获取了JSON数据。 还经历了本教程
并且遇到了以下课程:
<?php use Illuminate\Database\Seeder; use App\User; class PortletTableSeeder extends Seeder { public function run() { $json = File::get("database/data/portlets.json"); $data = json_decode($json); foreach ($data as $obj) { 'id' => $obj->id, 'html_code' => $obj->html_code, 'dummy_data' => $obj->dummy_data, //more objects.. )); } } } ?>这是执行此操作的正确方法吗? 并将其调用到刀片文件中,例如,如果gulpfile中的主题/ portlet的ID可以是这样的话,我就有名称的mixstyles:
<link href="css/{{$id}}.css" rel="stylesheet" type="text/css" />I'm trying to build a website builder, where I want to store HTML structure of the plugins/portlets manually, where user can have the structure and whatever editable data they are inserting, gets stored into database using serialize in the controller, now I came to know MySQL doesn't hold html data or say it is unsafe to store, I decided to store the basic structure into JSON format into a separate file, Now I don't want to have these JSON files in my public folder destination, I went through the Seeder documentation and tutorial to find path of the file and get the JSON data. Also went through this tutorial
and came across following class:
<?php use Illuminate\Database\Seeder; use App\User; class PortletTableSeeder extends Seeder { public function run() { $json = File::get("database/data/portlets.json"); $data = json_decode($json); foreach ($data as $obj) { 'id' => $obj->id, 'html_code' => $obj->html_code, 'dummy_data' => $obj->dummy_data, //more objects.. )); } } } ?>Is it the correct way of executing this? and calling it into blade file for example I have mixstyles by the name if id of the theme/portlet in gulpfile can I have like this:
<link href="css/{{$id}}.css" rel="stylesheet" type="text/css" />最满意答案
我认为最好的方法是在前端管理HTML代码(使用刀片)。 从DB获取数据集并在前端创建动态页面。
您可以设计单独的刀片文件并动态加载。
public function create() { $data = Portlet::get(); if(condition) return view('design.form1',compact('data')); else return view('design.form2',compact('data')); }如果你想在mysql DB中保存json数据,请点击链接。
如何在MySQL数据库中使用JSON数据字段
I think best way to do this is manage HTML code in front end (using blade). Get data set from DB & create dynamic pages in front end.
You can design separate blade files & load in dynamically.
public function create() { $data = Portlet::get(); if(condition) return view('design.form1',compact('data')); else return view('design.form2',compact('data')); }If you want to keep json data in mysql DB please follow the link.
How to Use JSON Data Fields in MySQL Databases
更多推荐
发布评论