简体   繁体   English

使用javascript / php保存配置信息

[英]Save configuration information using javascript/php

I am working with php and heatmap js to generate a heat-map. 我正在使用php和heatmap js来生成热图。

I was thinking of going down the path of allowing the user to upload a floor-map jpg file initially and then allow him to add the sensor names to different locations in the floor-map. 我正在考虑沿允许用户首先上载楼层地图jpg文件,然后允许他将传感器名称添加到楼层地图中不同位置的路径。

Once the sensor locations are specified, I need to save that configuration to an XML file. 指定传感器位置后,我需要将该配置保存到XML文件。 Once I have this set of information (img_id, [sensorid1,x1,y1], [sensorid2,x2,y2],..,[sensoridn,xn,yn]), I can query my database for the latest values of sensors and then display as heat-map on the image (on the specific sensors' x and y coordinates) real-time. 一旦有了这组信息(img_id,[sensorid1,x1,y1],[sensorid2,x2,y2],..,[sensoridn,xn,yn]),就可以查询数据库以获取传感器的最新值和然后作为热图实时显示在图像上(在特定传感器的x和y坐标上)。

I would like to know if saving the configuration as XML is the right way of doing it. 我想知道将配置另存为XML是否是正确的方法。 Is there there a better way of temporarily storing the information using javascript/PHP? 有没有更好的方法来使用javascript / PHP临时存储信息?

There are likely a bunch of ways to solve this. 有很多种方法可以解决此问题。 My preference would be for JSON, as it is natively supported by Javascript and PHP. 我的首选是JSON,因为Javascript和PHP本身支持它。 It is also MUCH easier to read and write. 它也很容易读写。

When you say "saving", what do you mean? 当您说“储蓄”时,您是什么意思? If you need it to be stored server side, then creating DB entities that the data structure can be mapped to and stored in will be far better than trying to create files server-side. 如果需要将其存储在服务器端,那么创建可以将数据结构映射并存储在其中的数据库实体比尝试在服务器端创建文件要好得多。 Depending on how the app gets hosted, you may not have permission to do that, and if your server ever goes away you could loose that data (However, there are safe ways to create files using a service like AWS S3). 根据托管应用程序的方式,您可能无权执行此操作,并且如果服务器消失了,您可能会丢失该数据(但是,有一些安全的方法可以使用AWS S3等服务来创建文件)。 Storing it in a database not only gives you a single place to worry about backups, but also lets you query the data in interesting and powerful ways (SQL etc) easily, without having to figure out how to do that for files with every new query. 将其存储在数据库中,不仅使您可以担心一个备份,而且还可以轻松轻松地以有趣且功能强大的方式(SQL等)查询数据,而无需弄清楚如何对每个新查询执行文件操作。

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

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