PHPackages                             indextank/yii2-plugin-env - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. indextank/yii2-plugin-env

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

indextank/yii2-plugin-env
=========================

PHP DotEnv for Yii2 framework

2.3(6y ago)089MITPHPPHP &gt;=7.0.0

Since Oct 10Pushed 6y ago1 watchersCompare

[ Source](https://github.com/indextank/yii2-plugin-env)[ Packagist](https://packagist.org/packages/indextank/yii2-plugin-env)[ RSS](/packages/indextank-yii2-plugin-env/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (9)Dependencies (1)Versions (10)Used By (0)

Yii2 DotEnv
===========

[](#yii2-dotenv)

[![Build Status](https://camo.githubusercontent.com/4cb08950ee3e4268fc81df305ed310b41815603dba08355ae647aa9fb8f9eacb/68747470733a2f2f7472617669732d63692e6f72672f696e64657874616e6b2f796969322d706c7567696e2d656e762e737667)](https://travis-ci.org/indextank/yii2-plugin-env)[![Latest Stable Version](https://camo.githubusercontent.com/2067a782e7ddb08e88c886ac93d18a1b087b7f2e73bc7f03abb53fb8b18c3682/68747470733a2f2f706f7365722e707567782e6f72672f696e64657874616e6b2f796969322d706c7567696e2d656e762f762f737461626c652e737667)](https://packagist.org/packages/indextank/yii2-plugin-env)[![Total Downloads](https://camo.githubusercontent.com/c1d031112b4d56bd8c415c7b18d04c08576b89aa39553df578117198ea34474a/68747470733a2f2f706f7365722e707567782e6f72672f696e64657874616e6b2f796969322d706c7567696e2d656e762f646f776e6c6f6164732e737667)](https://packagist.org/packages/indextank/yii2-plugin-env)[![Latest Unstable Version](https://camo.githubusercontent.com/36693f28a32954c50c6616b57dc68d2eb0c0ab54f21a30c107b34f4bfb8bbb57/68747470733a2f2f706f7365722e707567782e6f72672f696e64657874616e6b2f796969322d706c7567696e2d656e762f762f756e737461626c652e737667)](https://packagist.org/packages/indextank/yii2-plugin-env)[![License](https://camo.githubusercontent.com/254182edb78fbc3b91f16cd0f166d0fa4b25a3e24bfc8936e83c15b310d9c713/68747470733a2f2f706f7365722e707567782e6f72672f696e64657874616e6b2f796969322d706c7567696e2d656e762f6c6963656e73652e737667)](https://packagist.org/packages/indextank/yii2-plugin-env)

Yii 2 框架添加.env功能，实现类似于Lavaral框架中的.env功能。使框架配置更简单，更利于维护。本项目基于yiithings/yii2-dotenv。

本项目内含2个全局调试方法: p()和dd()，替代echo()、print\_r()等输出函数;

```
p($a, $b):打印变量，支持数组，格式化显示，不中断打印后续的输出，类似于:echo "";print_r($a);echo "----";print_r($b);
dd($a):打印变量，支持数组，格式化显示，中断打印后续的输出，类似于:echo "";print_r($A);exit()

```

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

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
-----

[](#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.

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~26 days

Recently: every ~4 days

Total

9

Last Release

2240d ago

Major Versions

1.4 → 2.02020-04-25

### Community

Maintainers

![](https://www.gravatar.com/avatar/dc004ab3995a638653a1453e11d76a71e30adaa87e050ed083dd2f2dedb8bc5e?d=identicon)[indextank](/maintainers/indextank)

---

Tags

envdotenvyii2extension

### Embed Badge

![Health badge](/badges/indextank-yii2-plugin-env/health.svg)

```
[![Health](https://phpackages.com/badges/indextank-yii2-plugin-env/health.svg)](https://phpackages.com/packages/indextank-yii2-plugin-env)
```

###  Alternatives

[yiithings/yii2-dotenv

PHP DotEnv for Yii2 framework

40606.4k7](/packages/yiithings-yii2-dotenv)[bnomei/kirby3-dotenv

Kirby Plugin for environment variables from .env

4147.7k1](/packages/bnomei-kirby3-dotenv)[beebmx/kirby-env

Enable env variables to Kirby

2139.6k2](/packages/beebmx-kirby-env)[johannschopplich/kirby-helpers

Environment, SEO, and build utilities for Kirby CMS

287.7k](/packages/johannschopplich-kirby-helpers)[dotenv-org/phpdotenv-vault

Load environment variables from encrypted .env.vault files

1018.1k2](/packages/dotenv-org-phpdotenv-vault)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
