ck. ck. - 1 year ago 80
PHP Question

Best practice to create absolute URLs with Zend framework?

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.

Answer Source

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

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

// document root for 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

echo '//' . $this->getHelper('ServerUrl')->getHost() . $this->baseUrl('css/base.css');
//will return protocol relative URL //
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download