PHPackages                             abahrami13/yii2-facades - 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. abahrami13/yii2-facades

ActiveYii2-extension

abahrami13/yii2-facades
=======================

Facades support for Yii 2 application components &amp; classes like Laravel

1.0.0(2y ago)33MITPHP

Since Mar 25Pushed 2y ago1 watchersCompare

[ Source](https://github.com/aBahrami13/yii2-facades)[ Packagist](https://packagist.org/packages/abahrami13/yii2-facades)[ Docs](https://github.com/abahrami13/yii2-facades)[ RSS](/packages/abahrami13-yii2-facades/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

yii2-facades
============

[](#yii2-facades)

Facades support for Yii 2 application components &amp; classes like Laravel

🟡 Installation
--------------

[](#-installation)

### Step 1

[](#step-1)

Run `composer require abahrami13/yii2-facades` command.

### Step 2

[](#step-2)

Add `abahrami13\facades\RegisterFacadeAutoloader` to the `bootstrap` array in the configuration file (`config/web.php` in the basic template).

🟡 Usage
-------

[](#-usage)

### 🔷 Components facades namespaces

[](#-components-facades-namespaces)

#### 1) Yii2 Components

[](#1-yii2-components)

To use component facade, just import a class started with `facades\` followed by the component id. For example for using facade of request component just import `facades\Request`:

`use facades\Request;`

#### 2) Other Classes

[](#2-other-classes)

To use facade for other classes, just add `facades\` to the start of the class namespace.

For example, for using facade for the `app\models\LoginForm` class, just import `facades\app\models\LoginForm` class

### 🔷 Utilizing Facades

[](#-utilizing-facades)

Just call the desired method statically &amp; enjoy :)

##### For components:

[](#for-components)

`Request::get('foo')` is equal to `Yii::$app->request->get('foo')`

##### For other classes

[](#for-other-classes)

`LoginForm::rules()`

is equal to

`$loginForm = new LoginForm();`

`$loginForm->rules()`

🟡 More Examples
---------------

[](#-more-examples)

### 🔷 Facades for Yii2 Components

[](#-facades-for-yii2-components)

#### 🔸 Generate random string

[](#-generate-random-string)

##### before

[](#before)

`$random = Yii::$app->security->generateRandomString(128);`

##### after

[](#after)

import: `use facades\Security;`

`$random = Security::generateRandomString(128);`

#### 🔸 Add Flash to session

[](#-add-flash-to-session)

##### before

[](#before-1)

`Yii::$app->session->addFlash('success', 'Wow, Yii is great');`

##### after

[](#after-1)

import: `use facades\Session;`

`Session::addFlash('success', 'Wow, Yii is great');`

#### 🔸 Fetch all users

[](#-fetch-all-users)

##### before

[](#before-2)

`Yii::$app->db->createCommand('SELECT * FROM user')->queryAll();`

##### after

[](#after-2)

import: `use facades\Db;`

`Db::createCommand('SELECT * FROM user')->queryAll();`

#### 🔸 Format currency

[](#-format-currency)

##### before

[](#before-3)

`Yii::$app->formatter->asCurrency(123456.78, 'USD');`

##### after

[](#after-3)

import: `use facades\Formatter;`

`Formatter::asCurrency(123456.78, 'USD');`

### 🔷 Facades for other classes

[](#-facades-for-other-classes)

#### 🔸 Call none static methods on other classes

[](#-call-none-static-methods-on-other-classes)

##### before

[](#before-4)

import: `use app\classes\Greeting;`

`$obj = new Greeting();`

`$obj->sayHello('Mr. Mahan');`

##### after

[](#after-4)

import: `use facades\app\classes\Greeting;`

`Greeting::sayHello('Mr. Mahan');`

#### 🔸 Call none static methods on a model

[](#-call-none-static-methods-on-a-model)

##### before

[](#before-5)

import: `use app\models\Post;`

`$post = new Post();`

`$titleLabel = $post->getAttributeLabel('title');`

##### after

[](#after-5)

import: `use facades\app\models\Post;`

`$titleLabel = Post::getAttributeLabel('title');`

🟡 Available Facades
-------------------

[](#-available-facades)

- All components that are defined in the components array of config file, are supported.
- All Classes (including models, Yii classes, your custom classes &amp; ...) are supported

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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

Unknown

Total

1

Last Release

779d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/93e182f4f811459482544f1df1ad987f93ac2ecf49204a3cdb51bfdea6dee78f?d=identicon)[aBahrami13](/maintainers/aBahrami13)

---

Top Contributors

[![aBahrami13](https://avatars.githubusercontent.com/u/29228883?v=4)](https://github.com/aBahrami13 "aBahrami13 (4 commits)")

---

Tags

laravelfacadeyii2yiifacadesyii2-facades

### Embed Badge

![Health badge](/badges/abahrami13-yii2-facades/health.svg)

```
[![Health](https://phpackages.com/badges/abahrami13-yii2-facades/health.svg)](https://phpackages.com/packages/abahrami13-yii2-facades)
```

###  Alternatives

[dragon-code/support

Support package is a collection of helpers and tools for any project.

238.7M101](/packages/dragon-code-support)[yii2tech/illuminate

Yii2 to Laravel Migration Package

11315.1k](/packages/yii2tech-illuminate)[gevman/yii2-router

Elegant Route definitions for Yii2

504.9k](/packages/gevman-yii2-router)

PHPackages © 2026

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