Support

Find answers, guides, and tutorials to supercharge your content delivery.

CakePHP CDN Integration

Updated on October 4, 2018

This tutorial helps you with integrating KeyCDN into your CakePHP CDN installation. You can use either a Pull or Push Zone but in most cases a Pull Zone is sufficient. The following example will work for CakePHP version 2.4 or higher. Learn more about the global configuration variables. This tutorial is based on the official CakePHP documentation about using a CDN.

  1. Create a Pull Zone before you start the CakePHP CDN integration.

  2. Define the base URL variables in your ./Config/bootstrap.php config file.

    ...
    Configure::write('App.imageBaseUrl', 'http://example-hexid.kxcdn.com/img/');
    Configure::write('App.cssBaseUrl', 'http://example-hexid.kxcdn.com/css/');
    Configure::write('App.jsBaseUrl', 'http://example-hexid.kxcdn.com/js/');
    ...
    

    Use your Zone URL or Zone Alias plus the web path to the relevant public directory under webroot.

  3. Use the HTML helper to include your assets in your views or template.

    HtmlHelper::css

    <?php echo $this->Html->css('your-css'); ?>
    

    Will output:

    <link rel="stylesheet" type="text/css" href="http://example-hexid.kxcdn.com/css/your-css.css" />
    

    HtmlHelper::image

    <?php echo $this->Html->image('your-logo.png', array('alt' => 'Your Logo')); ?>
    

    Will output:

    <img src="http://example-hexid.kxcdn.com/img/your-logo.png" alt="Your Logo" />
    

    HtmlHelper::script

    <?php echo $this->Html->script('your-js'); ?>
    

    Will output:

    <script type="text/javascript" href="http://example-hexid.kxcdn.com/js/your-js.js"></script>
    
  4. Check in the HTML source code if your assets are loading from KeyCDN.

Supercharge your content delivery 🚀

Try KeyCDN with a free 14 day trial, no credit card required.

Get started
KeyCDN uses cookies to make its website easier to use. Learn more