开发者

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:

  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.开发者_如何学Python

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)


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')?>" ... />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜