15
A
回答
21
2
这取决于你想如何存储你的配置。你可以包含一个php文件,其中包含以下内容:
$config['stuff'] = "value";
但是你也可以使用config(ini)文件或xml文件。 PHP具有可用于读取配置文件或xml文件的标准功能,所以这也很容易。
9
你可以有配置文件,然后包括它在每个脚本,像吉荣告诉你:
的config.inc.php
$config['dbname'] = 'myDB';
$config['dbuser'] = 'user';
...
然后在您的脚本
include_once('config.inc.php');
你也可以在你有一个模型的地方使用继承例如使用配置,然后您可以扩展该模型类。
2
您可以使用auto_prepend_file
在每个正在执行的PHP脚本中预先设置您的设置。它位于php.ini
之内,或者您可以使用.htaccess
(php_value auto_prepend_file "path/mysettings.php"
)或使用ini_set()
。该文件必须是有效的或现有的。
可能的重复http://stackoverflow.com/questions/2237291/php-reading-file – Gordon 2010-04-09 15:42:09
还有[serialize](http://php.net/manual/en/function.serialize.php)。 – spraff 2012-01-27 14:32:36