inquid/yii2-dotenv

PHP DotEnv for Yii2 框架

安装: 251

依赖: 1

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 16

开放问题: 1

类型:yii2-extension

1.0.2 2018-04-03 03:02 UTC

This package is auto-updated.

Last update: 2024-09-16 02:40:37 UTC


README

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

PHP DotEnv for Yii2 框架。

安装

安装此扩展的首选方式是通过 Composer

运行以下命令:

php composer.phar require --prefer-dist yiithings/yii2-dotenv "*"

或者

"yiithings/yii2-dotenv": "*"

将以下内容添加到你的 composer.json 文件的 require 部分:

用法

扩展安装后,只需在代码中使用即可

[
    'db' => [
        'password' => env('DB_PASS'),
    ],
]

env 函数将自动加载 .env 文件,它使用以下搜索机制

If there is a Yii class, then pass the alias @vendor or @app or @yii, Otherwise 
according to the project directory to determine.

但是,如果你的应用程序的 vendor 目录是符号链接,并且在调用 env 函数之前你没有注册 @vendor 或 @app 别名,则项目将无法运行。因此,你应该在调用 env 函数之前设置 @vendor 别名。