Source for: 'library/MkohZf/View/Helper/BaseUrl.php'
<?php
/**
* View helper to give the base url of the application
* @author mkoh
*/
class MkohZf_View_Helper_BaseUrl
{
/**
* Returns the base url (public root directory) of the application
* Usually the directory where the index.php is located
*
* @param $absoluteUrl boolean Whether add the protocol and hostname or not. Usually the path is enough.
* @return string
*/
function baseUrl($withHostname = false)
{
$baseUrl = Zend_Controller_Front::getInstance()->getBaseUrl();
if($withHostname) {
$server = Zend_Controller_Front::getInstance()->getRequest()->getServer();
list($protocol) = split('/', $server['SERVER_PROTOCOL']);
$absoluteUrl = strtolower(trim($protocol)) . '://' . $server['HTTP_HOST'];
$baseUrl = $absoluteUrl.$baseUrl;
}
return $baseUrl;
}
}
Comments
No comments, why not write one?