Zend Framework Source Code Snippets

CDN View Helper

class Galahad_View_Helper_Cdn extends Zend_View_Helper_Abstract 
{
	static $_types = array(
		'default' => '',
		'images'  => '/images',
		'styles'  => '/styles',
		'scripts' => '/scripts',
	);
	
	static function setTypes($types)
	{
		self::$_types = $types;
	}
	
	public function cdn($type = 'default')
	{
		if (!isset(self::$_types[$type])) {
			throw new Exception('No CDN set for resource type ' . $type);
		}
		
		return self::$_types[$type];
	}
}

Comments

You must login before commenting on a snippet. If you do not have an account, please register.

Setup:

$types = array(
'images' => 'http://me.cachefly.net/images',
'styles' => 'http://static.me.com/st',
'scripts' => 'http://s3.amazonaws.com/mescripts',
);
Galahad_View_Helper_Cdn::setTypes($types);
$view->addHelperPath('Galahad/View/Helper', 'Galahad_View_Helper');

In View/Layout File:

<img src="<?=$this->cdn('images')?>/myimg.png" />

Created:
inxilpro inxilpro
9 months ago
Edited:
inxilpro inxilpro
9 months ago
Revision Id:
106
Edit Message:
Initial Release
Tags:
view helper cdn
Comments:
0
Points:
0 (2 votes)

History

r106

Initial Release

inxilpro inxilpro
9 months ago