Skip to main content

Yii 2.0 Medianova CDN Integration

Yii is an open source, object-managed and component-based MVC structure, a PHP web application framework. Yii released the first version in 2006, 2.0 version was released in 2013.

Follow the steps below to integrate Yii 2.0 with Medianova CDN.

  1. Install the required extension with the aid of Composer. Run thecomposer.phar require –prefer-dist blacksmoke26/yii2cdn “*” or add “blacksmoke26/yii2cdn”: “*” to the require section of your composer.json file.

  2. Create the property called “cdn” under the root folder.

  3. Open the (@app/config/web.php) file on the terminal. And then add a property called “cdn” under the “Component” section with the aid of below the code.

CODE
// ...
'components' => [
    // ...
    'cdn' => [
        'class' => '\yii2cdn\Cdn',
        'baseUrl' => '/cdn',
        'basePath' => dirname(dirname(__DIR__)) . '/cdn',
        'components' => [
            'style' => [
                'css' => [
                    [
                        'css/style.css', // offline
                        '@cdn' => 'https://yourwebsite.mncdn.com/css/style.css', // online version
                    ]
                ]
            ]
        ],
    ],
  // ...
],
// ...
  1. Open any view file and paste the following line.

CODE
//...
Yii::$app->cdn->get('style')->register();
//...
  1. Check your HTML source code for be sure rewritten asset URL with making the CDN URL instead of Origin.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.