Yii2cdn ¶
- Resources
- Installation
- Usage
- I. Installing a library
- II. Add a component
- III. Registering assets
- IV. Final moment
A Yii Framework 2 component for using assets in different environments (Local/CDNs)
Resources ¶
- Project: https://github.com/blacksmoke26/yii2cdn/
- Wiki: https://github.com/blacksmoke26/yii2cdn/wiki
- Class Reference: http://blacksmoke26.github.io/yii2cdn/api/
- Issues: https://github.com/blacksmoke26/yii2cdn/issues
Installation ¶
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist blacksmoke26/yii2cdn "*"
or add
"blacksmoke26/yii2cdn": "*"
to the require section of your composer.json file.
Usage ¶
Info: This tutorial will demonstrate how to use Font-Awesome library in a production (online/CDN) or development (local/offline) environment.
I. Installing a library ¶
- Create a
cdndirectory under your root folder. - Install or download
FortAwesome/Font-Awesomelibrary undercdndirectory.- Path should be
/cdn/font-awesome.
- Path should be
II. Add a component ¶
- Open
@app/config/main.phpin your code editor. - Add a new propery
cdnundercomponentssection like the following code:
// ...
'components' => [
// ...
'cdn' => [
'class' => '\yii2cdn\Cdn',
'baseUrl' => '/cdn',
'basePath' => dirname(dirname(__DIR__)) . '/cdn',
'components' => [
'font-awesome' => [
'css' => [
[
'css/font-awesome.min.css', // offline version
'@cdn' => '//cdnjs.cloudflare.com/ajax/libs/font-awesome/'
. '4.5.0/css/font-awesome.min.css', // online version
]
]
]
],
],
// ...
],
// ...
III. Registering assets ¶
- Open any view file and paste the following line:
//...
Yii::$app->cdn->get('font-awesome')->register();
//...
IV. Final moment ¶
- Browse the action url in your browser and check the view souce.
Now it's time to play around, See ya!
User Contributed Notes
Leave a comment
If you have any questions, please ask in the forum instead.
Join the conversation to share a note.