foodette/yii1-dotenv

YIi 1 phpdotenv extension

1.1 2018-10-30 16:03 UTC

This package is auto-updated.

Last update: 2024-04-29 04:03:07 UTC


README

Latest Stable Version License

PHP DotEnv for Yii 1.1 Framework.

Installation

The preferred way to install this extension is through composer.

Either run

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

or add

"foodette/yii1-dotenv": "*"

to the require section of your composer.json file.

Usage

Once the extension is installed, simply use the provided env() function in your code :

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

The env function will autoload .env file, it uses the following search mechanism :

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.

Best is to set the vendor or root alias before calling env() function.

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