indextank / yii2-plugin-env
PHP DotEnv for Yii2 framework
Installs: 85
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- php: >=7.0.0
- vlucas/phpdotenv: ^4.1
README
Yii 2 框架添加.env功能,实现类似于Lavaral框架中的.env功能。使框架配置更简单,更利于维护。本项目基于yiithings/yii2-dotenv。
本项目内含2个全局调试方法: p()和dd(),替代echo()、print_r()等输出函数;
p($a, $b):打印变量,支持数组,格式化显示,不中断打印后续的输出,类似于:echo "<pre>";print_r($a);echo "----";print_r($b);
dd($a):打印变量,支持数组,格式化显示,中断打印后续的输出,类似于:echo "<pre>";print_r($A);exit()
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist indextank/yii2-plugin-env "*"
or add
"indextank/yii2-plugin-env": "*"
to the require section of your composer.json
file.
Usage
Once the extension is installed, simply use it in your code by :
[
'db' => [
'password' => penv('DB_PASS'),
],
]
The env function will autoload .env file, it uses the following search mechanism:
If there is a Yii class, then pass the alias @vendor or @app or @yii, Otherwise
according to the project directory to determine.
But, if your application vendor directory is a symbol link and you no registered @vendor or @app alias before call env function, the project will not working. So you should set the @vendor alias before calling env function.