Download the PHP package jimchen/yii2-facades without Composer
On this page you can find all versions of the php package jimchen/yii2-facades. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jimchen/yii2-facades
More information about jimchen/yii2-facades
Files in jimchen/yii2-facades
Package yii2-facades
Short Description Laravel like facades support for Yii 2 application components
License MIT
Informations about the package yii2-facades
Facades for Yii 2
Laravel like facades support for Yii 2 application components. Just what you want: simple, extensive and with an IDE auto completion support via PHPDoc so you won't be disappointed.
Table of contents
- Installation
- Usage
- Generate random string
- Fetch all users (just an example!)
- Format currency
- Access properties
- Available facades
- Helpers
- Cache
- cache
- get
- Response
- bare
- html
- json
- jsonp
- raw
- xml
- Extending
Installation
The preferred way to install this extension is through composer.
Either run
Usage
Basically you install the extension and start using it like you do with all normal Yii 2 application components but with a shorter simpler syntax, let's take a look (in case you wonder, all default facades, including an abstract base Facade
reside under a jimchen\facades
namespace):
Generate random string
Before:
After:
Fetch all users (just an example!)
Before:
After:
Format currency
Before:
After:
Access properties
Any class public property $foo
can be got via an accessor:
And set:
Available facades
Name | Facaded component alias | Component/interface |
---|---|---|
Asset |
Yii::$app->assetManager |
yii\web\AssetManager |
Auth |
Yii::$app->auth |
yii\rbac\ManagerInterface |
Cache |
Yii::$app->cache |
yii\caching\Cache |
Db |
Yii::$app->db |
yii\db\Connection |
Error |
Yii::$app->errorHandler |
yii\console\ErrorHandler |
yii\web\ErrorHandler |
||
Formatter |
Yii::$app->formatter |
yii\i18n\Formatter |
I18n |
Yii::$app->i18n |
yii\i18n\I18N |
Log |
Yii::$app->log |
yii\log\Dispatcher |
Mailer |
Yii::$app->mailer |
yii\swiftmailer\Mailer |
Redis |
Yii::$app->redis |
yii\redis\Connection |
Request |
Yii::$app->request |
yii\console\Request |
yii\web\Request |
||
Response |
Yii::$app->response |
yii\console\Response |
yii\web\Response |
||
Router |
Yii::$app->urlManager |
yii\web\UrlManager |
Security |
Yii::$app->security |
yii\base\Security |
Session |
Yii::$app->session |
yii\web\Session |
Url |
Yii::$app->urlManager |
yii\web\UrlManager |
User |
Yii::$app->user |
yii\web\User |
View |
Yii::$app->view |
yii\web\View |
Helpers
Some facades also contain useful helpers to make a development more quick and elegant.
Cache
cache
Retrieves a value using the provided key or the specified default value if the value is not cached. If the value is not in the cache, it will be cached. The default value can also be a closure:
get
Retrieves a value using the provided key and returns it or the specified default value which can also be a closure:
Response
bare
Returns an empty response with optional headers:
html
Returns a HTML response with optional headers:
json
Returns a JSON response with optional headers:
jsonp
Returns a JSONP response with optional headers:
raw
Returns a response with data "as is" with optional headers:
xml
Returns a XML response with optional headers:
Extending
If you want a new facade, it's fast and easy, imagine you want to bring a YourFacadeName
facade:
Then whenever you call
it will be executed as