Skip to main content

CodeIgniter Medianova CDN Integration

CodeIgniter; It is an open-source PHP framework that was released in February 2006 and does not require the use of the MVC model. It has no restrictive rules for programming and naming. It is preferred frequently by developers because of its strong structure and lack of restrictive rules.

Medianova supports CDN CodeIgniter integration. The content you specify with integration will now be delivered from Medianova servers scattered around the world. In this way, you will increase the performance of your application. Then why are you losing time!

You can integrate the CodeIgniter with CDN easily and quickly the following steps you follow.

Note: We recommend back up your files and database before they integrate

  1. First of all, create a zone for your account.

  2. Load the URL Helper and open the application/config/autoload.php file. Search this item.

CODE
s$autoload['helper'] = array();
  1. Open the application/config/config.php file.

  • Add $config[‘mncdn_url’] item in file.

CODE
/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
|    http://example.com/
|
| WARNING: You MUST set this value!
|
| If it is not set, then CodeIgniter will try guess the protocol and path
| your installation, but due to security concerns the hostname will be set
| to $_SERVER['SERVER_ADDR'] if available, or localhost otherwise.
| The auto-detection mechanism exists only for convenience during
| development and MUST NOT be used in production!
|
| If you need to allow multiple domains, remember that this file is still
| a PHP script and you can easily do that on your own.
|
*/
$config['base_url'] = 'https://www.example.com/';

/*
|--------------------------------------------------------------------------
| MedianovaCDN URL
|--------------------------------------------------------------------------
|
| URL to your Medianova CDN Zone. Use your Zone URL or Zone Alias,
| WITH a trailing slash:
|
|    https://img-medianova.mncdn.com/
|
| WARNING: You MUST set this value to enable MedianovaCDN!
|
| If it is not set, then the extended URL Helper will use your default
| Base Site URL instead.
|
*/
  • Define the “Helper URL” that helps to work with URLs. Search this item for extending the own prefix.

CODE
$config['subclass_prefix'] = 'MY_';
  • Change the prefix name be its “ext.”

CODE
$config['subclass_prefix'] = 'ext.';
  1. Extend exist base_url Create the application/helpers/ext.url_helper.php file for write on this function.

CODE
<?php
/*
| Base URL
|
| Overwrite the base_url function to support
| loading designated content from MedianovaCDN.
*/
function base_url($file)
{
    $currentInstance =& get_instance();

    $mncdnUrl = $currentInstance->config->item('mncdn_url');

    // define any extension that should use your MedianovaCDN URL
    $extensions = array('css', 'js', 'svg', 'jpg', 'jpeg', 'png', 'gif', 'pdf');
    $pathParts = pathinfo($file);

    if (!empty($mncdnUrl) && in_array($pathParts['extension'], $extensions)) {
        return $mncdnUrl . $file;
    }

    return $currentInstance->config->base_url($file);
  1. Make sure to load the designated contents from the Medianova CDN. Check application HTML source code for verifying.

CODE
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Welcome to CodeIgniter</title>
        <link rel="stylesheet" href="https://img-medianova.mncdn.com/assets/css/style.css">
    </head>
    <body>
        <div id="container">
            <h1>Welcome to CodeIgniter!</h1>
            <div id="body">
                <img src="https://img-medianova.mncdn.com/assets/img/logo.svg" alt="logo">
                <p>The page you are looking at is being generated dynamically by CodeIgniter.</p>
            </div>
        </div>
        <script type="text/javascript" src="https://img-medianova.mncdn.com/assets/js/app.js"></script>
    </body>
</html>
JavaScript errors detected

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

If this problem persists, please contact our support.