Skip to main content

Zend Medianova CDN Integration

Zend is an open-source, object-oriented PHP web application framework. A Zend plug-in makes CDN integration easy.

The following steps describe the integration between Medianova CDN and Zend.

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

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

  2. To create links pointing to the Medianova CDN URL, create the Zend plug-in below     **Change the your-cdn-url.com with your CDN URL.

CODE
class MnCDN_Plugin extends Zend_Controller_Plugin_Abstract {
    public function preDispatch(Zend_Controller_Request_Abstract $request) {
        // enable CDN links for development env
        $enable_cdn_dev = (bool) true;
        // MnCDN URL or Zone Alias
        $cdn_hostname = 'your-cdn-url.com';

        if ((APPLICATION_ENV == 'production') || $enable_cdn_dev)) {
            // SSL or not
            if ($request->isSecure()) {
                Zend_Registry::set('cdn_protocol', 'https');
            } else {
                Zend_Registry::set('cdn_protocol', 'http');
            }
        Zend_Registry::set('cdn_on', true);
        Zend_Registry::set('cdn_hostname', $cdn_hostname);
        } else {
            Zend_Registry::set('cdn_on', false);
        }
        return true;
    }
}
  1. Create Zend view helper.

CODE
class MnCDN_Helper extends Zend_View_Helper_Abstract {
    public function cdn($url) {
        if (empty($url))
            throw new Exception('Path is missing');

        $pattern = '/^http/i';
        if (preg_match($pattern, $url)) {
            throw new Exception('Invalid usage. ' .
                'Use: /htdocs/images instead of the full URL ' .
                'http://your-website.com/htdocs/images.'
            );
        }

        $pattern = '|^/|';
        if (!preg_match($pattern, $url)) {
            $url = '/' . $url;
        }

        if (!Zend_Registry::get('cdn_on')) {
            return $url;
        } else {
            $cdn_hostname = Zend_Registry::get('cdn_hostname');
            $cdn_protocol = Zend_Registry::get('cdn_protocol');
            $uri = $cdn_protocol . '://' . $cdn_hostname . $url;

            return $uri;
        }
    }
}
  1. Use the CDN helper in the view.

CODE
<img alt="Medianova CDN" src="<?php echo $this->cdn('//img-docsmedianova.mncdn.com/htdocs/images/medianova-logo.jpeg'); ?>" />
  1. Verify whether links with HTML source code show the CDN URL.

Note: You can use the https://docs.medianova.com/en/medianova-cdn-user-integration/ link to view the CDN URLs of your Zone.

JavaScript errors detected

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

If this problem persists, please contact our support.