Different way of referencing images/stylesheets based on development and production environment in Zend Framework?
I want to host images on separate sub-domain to avoid sending cookies with HTTP request.
There are two domains:
- mydomain.com - to serve all the content
- static.mydomain.com - to serve images and static content
Both domains are pointing to the same directory hierarchy.开发者_如何学Python
So is there any way to utilize Zend framework feature to:
- In development environment reference to static content locally
- In production environment use full domain name (static.mydomain.com)
Simplest solution would probably be to create a view helper, something along the lines of:
class My_View_Helper_AssetPath extends Zend_View_Helper_Abstract
{
public function assetPath($filename)
{
if (APPLICATION_ENV == 'production') {
$path = 'http://static.mydomain.com';
} else {
$path = '';
}
$path .= $filename;
return $path;
}
then in your templates:
<img src="<?=$this->assetPath('/images/logo.png')?>" ... />
精彩评论