yii2-cdn A Yii Framework 2 component for using assets in different environments (Local/CDNs)

Yii2cdn

  1. Resources
  2. Installation
  3. Usage
  4. I. Installing a library
  5. II. Add a component
  6. III. Registering assets
  7. IV. Final moment

A Yii Framework 2 component for using assets in different environments (Local/CDNs)

Resources

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

  1. Create a cdn directory under your root folder.
  2. Install or download FortAwesome/Font-Awesome library under cdn directory.
    • Path should be /cdn/font-awesome.

II. Add a component

  1. Open @app/config/main.php in your code editor.
  2. Add a new propery cdn under components section 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

  1. Open any view file and paste the following line:
//...
Yii::$app->cdn->get('font-awesome')->register();
//...

IV. Final moment

  1. Browse the action url in your browser and check the view souce.

Now it's time to play around, See ya!

0 0
1 follower
0 downloads
Yii Version: 2.0
License: Apache-2.0
Category: Others
Tags: cdn yii2
Developed by: junaidatari
Created on: Apr 20, 2016
Last updated: 8 years ago