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
- First of all, create a zone for your account
- 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
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; } }
- Create Zend view helper
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; } } }
- Use the CDN helper in the view
<img alt="Medianova CDN" src="<?php echo $this->cdn('//img-docsmedianova.mncdn.com/htdocs/images/medianova-logo.jpeg'); ?>" />
- 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