mako\URL


Description


URL helper.


Class methods


Toggle source

protected __construct()


Protected constructor since this is a static class.

Return value

NULL

protected function __construct()
{
	// Nothing here
}

Toggle source

public static base()


Returns the base URL of the application.

Return value

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;
}

Toggle source

public static to($route = '', $params = array ( ), $separator = '&')


Returns a mako framework URL.


Parameters

Type Description
string URL segments
array (optional) Associative array used to build URL-encoded query string
string (optional) Argument separator
Return value

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;
}

Toggle source

public static current($params = array ( ), $separator = '&')


Returns the current URL of the main request.


Parameters

Type Description
array (optional) Associative array used to build URL-encoded query string
string (optional) Argument separator
Return value

string

public static function current(array $params = array(), $separator = '&')
{
	return static::to(Request::route(), $params, $separator);
}