环境变量
设置环境变量 /.env
[DATABASE]
USERNAME = root
PASSWORD = 123456
获取环境变量 app/controller/Index.php
<?php
namespace app\controller;
use app\BaseController;
use think\facade\Env;
class Index extends BaseController
{
public function index()
{
$username = Env::get('database.username','root');
$password = Env::get('database.password');
$data = [
'username' => $username,
'password' => $password
];
return json_encode($data);
}
}
访问测试
http://codeit.org.cn/index
{“username”:“root”,“password”:“123456”}
1.在thinkphp\config\下新建一个test.php配置文件
.test.php文件内容
<?php
// 自定义配置文件
return [
'profile' =