标题可能令人困惑,因为我不确定如何解释这一点。我确定这是一个非常简单的解决方案。
我正在将所有静态图像、css、js 移动到 S3 - 所以现在它们可以通过
例如:
http://files.xyz.com/images/logo.gif
http://files.xyz.com/images/submit_button.gif
http://files.xyz.com/style/style.css
http://files.xyz.com/js/jquery.js
files.xyz.com 是指向 files.xyz.com.s3.amazonaws.com 的 CNAME
现在在我的 Zend 布局和 View 中 - 我正在使用完整的 URL 访问这些
例如
<img src="http://files.xyz.com/images/logo.gif"/>
我担心的是当我在本地主机上进行测试时 - 我不希望从 S3 而是从我的本地硬盘获取数据
所以我想做这样的事情。在我的 application.ini - 我应该能够指定
resources.frontController.imageUrl = http://localhost
当我部署时 - 只需将其更改为
resources.frontController.imageUrl = http://files.xyz.com
并在 View 中访问它
处理这个问题的最佳方法是什么
谢谢
最佳答案
创建 View 助手
public function imageUrl()
{
$config = Zend_Registry::get('config');
if($config->s3->enabled){
return $config->s3->rootPath;
}else{
return $this->view->baseUrl();
}
}
在应用程序.ini
s3.enabled = 1
s3.rootPath = https://xxxxx.s3.amazonaws.com
你可以这样调用
<img src="<?php echo $this->imageUrl();?>/images/logo.gif"/>
因此,您可以轻松启用/禁用 s3。
关于php - Zend - 更改用于部署的图像 URL 路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10881750/