1

I want to host images on separate sub-domain to avoid sending cookies with HTTP request.

There are two domains:

  1. mydomain.com - to serve all the content
  2. static.mydomain.com - to serve images and static content

Both domains are pointing to the same directory hierarchy.

So is there any way to utilize Zend framework feature to:

  1. In development environment reference to static content locally
  2. In production environment use full domain name (static.mydomain.com)
pixel
  • 24,905
  • 36
  • 149
  • 251

1 Answers1

2

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')?>" ... />
Tim Fountain
  • 33,093
  • 5
  • 41
  • 69
  • I've got another novice question - where I should put this "AssetPath" class? I'm putting it into application/view/helpers and I get `Fatal error: Uncaught exception 'Zend_Loader_PluginLoader_Exception' with message 'Plugin by name 'AssetPath' was not found in the registry; used paths: Zend_View_Helper_: Zend/View/Helper/;C:/Program Files/Zend/Apache2/htdocs/Myproject/application/views\helpers/'` – pixel Jun 26 '11 at 17:35
  • Actually my problem was solved in answer to following question http://stackoverflow.com/questions/2335545/how-to-add-a-view-helper-directory-zend-framework – pixel Jun 26 '11 at 20:03