简体   繁体   English

我应该在哪里存储一些项目参数?

[英]Where should I store some of my project's parameters?

I don't know where should I store some of the parameters of my PHP/MySQL website, like number of entries per page, number of viewers of website and etc. First I decided to store them in a MySQL table called for example parameter, but I think it is not a good approach because I realized that the settings and parameters of my website are just one entity and it is not standard to reserve a table for just one entity. 我不知道我应该在哪里存储PHP / MySQL网站的某些参数,例如每页条目数,网站的观看者人数等。首先,我决定将它们存储在称为参数的MySQL表中,但是我认为这不是一个好方法,因为我意识到我的网站的设置和参数只是一个实体,并且仅为一个实体保留表格是不标准的。 What solutions do you think should I use? 您认为我应该使用什么解决方案?

Use a configuration file. 使用配置文件。 Inside you code your parameters in some serialized form. 在内部,您以某种序列化形式对参数进行编码。 Might be JSON, but it is even easier if you use plain ini file syntax. 可能是JSON,但如果使用普通的ini文件语法,它甚至会更容易。 That way you can modify the file more easily. 这样,您可以更轻松地修改文件。 Start by reading php's ini file parsing method . 首先阅读php的ini文件解析方法

Well, there is several solutions, one as you say is to store the parameters of you project in a table, for example Drupal do it that way, implementing two functions: variable_get and variable_set to retrieve and store the values of parameters. 嗯,有几种解决方案,您所说的一种是将项目的参数存储在表中,例如Drupal就是这样做的,实现了两个函数: variable_getvariable_set用于检索和存储参数值。

Other frameworks use .ini or xml files. 其他框架使用.ini或xml文件。 I like the use of YAML files, as Symfony do, because is a clear format and you can parse it easily. 我喜欢像Symfony一样使用YAML文件,因为它是一种清晰的格式,您可以轻松解析它。

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

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