Symfony CDN Integration

This tutorial describes how to integrate KeyCDN into the MVC PHP framework Symfony. The integration is very easy with the following option. All you need is to set the base URL and reference it later when you load your assets.

  1. Create a pull zone before you start the Symfony CDN integration.
  2. Define the base URL in your app/config/config.yml config file.
    • Symfony 2.6
      framework:
          templating:
              packages:
                  keycdn:
                      base_urls:
                          http: ['http://cdn.foobar.com']
                          ssl:  ['https://secure.foobar.com']
    • Symfony 2.7
      framework:
          assets:
              packages:
                  keycdn:
                      base_urls: ['http://cdn.foobar.com', 'https://secure.foobar.com']
      
  3. Add your assets like this:
    <img src="{{ asset('your-image.jpg', 'keycdn') }}" alt="Your Image" >
  4. Check in the HTML source code if the URL of your assets is pointing correctly to KeyCDN.

Did you find another integration approach with Symfony we should mention here? Contact us and we will add it.

Leave A Comment?