我正在开发一个具有经典文件层次结构的 Zend Web 应用程序,即:
application/
docs/
library/
public/
tests/
由于该应用程序在具有不同服务器配置的不同计算机中使用,因此在视图脚本中我希望拥有独立于文档根目录工作的链接路径在 Web 服务器配置中设置。
示例如下:
主机 FOO 配置为将文档根目录指向 $APP/public/,因此浏览器 URL 将为“http:// myapp/"
主机 BAR 未像 FOO 那样配置,浏览器 URL 为“http://localhost/my/deep/path/to/$APP/public"
在视图脚本中,我想编写以下内容:
<img src="<?= $urlbase ?>images/logo.gif" />
显示 $APP/public/ 中的图像images/logo.gif,这样它就可以在 FOO 和 BAR 主机中工作。
我可以用什么来代替 $urlbase?
PS:我尝试使用:
<?= $this->url() ?>
但它没有考虑 url 中包含的控制器、操作和获取参数,即“http://myapp/index/login/”它返回“/index/login/”,而我需要它只返回“/”。
I'm developing a Zend web application with classic file hierarchy structure, ie:
application/
docs/
library/
public/
tests/
Since the app is used in different machine with different server configurations, In the view scripts I would like to have link paths that work independently from where the document root has been set in the web server configuration.
Examples follow:
Host FOO is configured to point the document root to $APP/public/, and so the browser url would be "http://myapp/"
Host BAR is not configured like FOO and the browser url is "http://localhost/my/deep/path/to/$APP/public"
In the view script I would like to write the following:
<img src="<?= $urlbase ?>images/logo.gif" />
to display an images which is in $APP/public/images/logo.gif, in such a way that it works both in FOO and in BAR hosts.
What do I use in place of $urlbase?
PS: I tried to use:
<?= $this->url() ?>
but it doesn't take into account the controllers, actions, and get parameters contained in the url, that is at "http://myapp/index/login/" it returns "/index/login/", while I need it to return just "/".
发布评论
评论(1)
使用 BaseUrl 帮助程序
Use the BaseUrl helper