URL helper.
Protected constructor since this is a static class.
NULL
protected function __construct()
{
// Nothing here
}
Returns the base URL of the application.
string
public static function base()
{
static $base = false;
if($base === false)
{
$base = Config::get('mako.base_url');
// Try to autodetect base url if its not configured
if($base === '' && isset($_SERVER['HTTP_HOST']))
{
$protocol = Request::isSecure() ? 'https' : 'http';
$script = $_SERVER['SCRIPT_NAME'];
$base = rtrim($protocol . '://' . $_SERVER['HTTP_HOST'] . str_replace(basename($script), '', $script), '/');
}
// Add index.php?
!Config::get('mako.clean_urls') && $base .= '/index.php';
}
return $base;
}
Returns a mako framework URL.
| Type | Description |
|---|---|
| string | URL segments |
| array | (optional) Associative array used to build URL-encoded query string |
| string | (optional) Argument separator |
string
public static function to($route = '', array $params = array(), $separator = '&')
{
$url = static::base() . '/' . $route;
if(!empty($params))
{
$url .= '?' . http_build_query($params, '', $separator);
}
return $url;
}
Returns the current URL of the main request.
| Type | Description |
|---|---|
| array | (optional) Associative array used to build URL-encoded query string |
| string | (optional) Argument separator |
string
public static function current(array $params = array(), $separator = '&')
{
return static::to(Request::route(), $params, $separator);
}