foodette/yii1-dotenv

YII 1 phpdotenv 扩展

1.1 2018-10-30 16:03 UTC

This package is auto-updated.

Last update: 2024-09-29 05:08:34 UTC


README

Latest Stable Version License

PHP DotEnv for Yii 1.1 框架。

安装

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

可以运行以下命令:

php composer.phar require --prefer-dist foodette/yii1-dotenv "*"

或者在您的 composer.json 文件的 require 部分添加以下内容:

"foodette/yii1-dotenv": "*"

to the require section of your composer.json file.

使用方法

扩展安装完成后,只需在您的代码中使用提供的 env() 函数即可

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

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

If there is a Yii class the autoloader will try and detect `vendor` or `root` alias, otherwise 
up to the project directory to determine dotenv path.

在调用 env() 函数之前,最好设置 vendorroot 别名。

Yii::setPathOfAlias('root', 'PATH/TO/PROJECT/ROOT');