使用Zend框架创建绝对URL的最佳实践? [英] Best practice to create absolute URLs with Zend framework?

查看:84
本文介绍了使用Zend框架创建绝对URL的最佳实践?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Zend框架创建绝对URL是否有最佳实践?我想知道是否有一些帮助器,或者这只是从$ _SERVER变量连接方案,主机等,然后添加Zend生成的相对路径。

Is there a best practice for creating absolute URLs using the Zend framework? I wonder if there is some helper or if this would just be concatenating the scheme, host, etc. from the $_SERVER variable and then add the relative path generated by Zend.

推荐答案

phpfour的方式还可以,但你必须检查https://,ftp://和mailto:too ... :)

phpfour's way is OK, but you have to check for https://, ftp:// and mailto: too... :)

我首选所有网址为root-absolute( /files/js/jquery.js )。 硬核zend方式是

I prefefer having all urls root-absolute (/files/js/jquery.js). The "hardcore zend way" is

<?php 
// document root for example.com is in /htdocs 
// but application's index.php resides in /htdocs/myapp/public
echo $this->baseUrl('css/base.css'); 
//will return /myapp/public/css/base.css

echo $this->serverUrl() . $this->baseUrl('css/base.css');
//will return http://www.example.com/myapp/public/css/base.css

echo '//' . $this->getHelper('ServerUrl')->getHost() . $this->baseUrl('css/base.css');
//will return protocol relative URL //www.example.com/myapp/public/css/base.css

这篇关于使用Zend框架创建绝对URL的最佳实践?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆