thinkphp6 获取.env文件以及config文件夹app.php的值
2022-11-24 11:10:29
175
{{single.collect_count}}
  1. 在本地测试时.env 优先于 config文件夹下的配置,部署环境中,.env 会被忽略,自动切换到 config 配置

  2. 对于.env文件,比如[DATABASE]下的HOSTNAME=127.0.0.1,获取方式如下:

    use think\facade\Env;return Env::get('database.hostname');
  3. 对于config文件夹下的配置,比如(database.php)下的hostname,获取方式如下:

    use think\facade\Config;return Config::get('database.connections.mysql.hostname');
  4. 判断.env文件与config文件夹下的配置是否存在,使用 has 方法判断:

    echo Env::has('database.hostname');echo Config::has('database.connections.mysql.hostname');存在返回1,不存在返回空
回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}