我已经将一些网站配置数据存储在一个config.json
文件中,其中包括数据库连接参数和路由等。像这样的东西:
{
"production" : { ... },
"test" : { ... },
"development" : { ... }
}
内容加载:
$config = json_decode(file_get_contents('config'), true);
但是,检查一些框架,我看到直接使用 PHP 脚本进行配置存储:
<?php
return array(
'production' => array( ... ),
'test' => array( ... ),
'development' => array( ... )
);
<?php $config = (require 'config.php');
哪种方法最好?