UrlHelper

Type
Class
Namespace
craft\helpers
Inherits
craft\helpers\UrlHelper
Since
3.0

Class Url

View source

Public Methods

MethodDescription
actionUrl()
baseCpUrl()Returns the Control Panel’s base URL (with a trailing slash) (sans-CP trigger).
baseRequestUrl()Returns the base URL (with a trailing slash) for the current request.
baseSiteUrl()Returns the current site’s base URL (with a trailing slash).
baseUrl()Returns either the current site’s base URL or the CP base URL, depending on the type of request this is.
cpHost()Returns the Control Panel's host.
cpUrl()Returns a CP URL.
getProtocolForTokenizedUrl()Returns what the scheme part of the URL should be (http/https) for any tokenized URLs in Craft (email verification links, password reset urls, share entry URLs, etc.
getSchemeForTokenizedUrl()Returns what the scheme part of the URL should be (http/https) for any tokenized URLs in Craft (email verification links, password reset urls, share entry URLs, etc.
host()Returns the host info for the CP or the current site, depending on the request type.
hostInfo()Parses a URL for the host info.
isAbsoluteUrl()Returns whether a given string appears to be an absolute URL.
isFullUrl()Returns whether a given string appears to be a "full" URL (absolute, root-relative or protocol-relative).
isProtocolRelativeUrl()Returns whether a given string appears to be a protocol-relative URL.
isRootRelativeUrl()Returns whether a given string appears to be a root-relative URL.
siteHost()Returns the current site’s host.
siteUrl()Returns a site URL.
stripQueryString()Removes the query string from a given URL.
url()Returns either a CP or a site URL, depending on the request type.
urlWithParams()Returns a URL with additional query string parameters.
urlWithProtocol()Returns a URL with a specific scheme.
urlWithScheme()Returns a URL with a specific scheme.
urlWithToken()Returns a URL with a 'token' query string param set to a given token.

actionUrl()

View source

Arguments

  • $path (string)
  • $params (array, string, null)
  • $scheme (string, null) – The scheme to use ('http' or 'https'). If empty, the scheme used for the current request will be used.

Returns

string

Signature

public static string actionUrl ( \craft\helpers\string $path = '', $params = null, \craft\helpers\string $scheme = null )

baseCpUrl()

Returns the Control Panel’s base URL (with a trailing slash) (sans-CP trigger).

View source

Returns

string

Signature

public static string baseCpUrl ( )

baseRequestUrl()

Returns the base URL (with a trailing slash) for the current request.

View source

Returns

string

Signature

public static string baseRequestUrl ( )

baseSiteUrl()

Returns the current site’s base URL (with a trailing slash).

View source

Returns

string

Throws

Signature

public static string baseSiteUrl ( )

baseUrl()

Returns either the current site’s base URL or the CP base URL, depending on the type of request this is.

View source

Returns

string

Throws

Signature

public static string baseUrl ( )

cpHost()

Returns the Control Panel's host.

View source

Returns

string

Signature

public static string cpHost ( )

cpUrl()

Returns a CP URL.

View source

Arguments

Returns

string

Signature

public static string cpUrl ( \craft\helpers\string $path = '', $params = null, \craft\helpers\string $scheme = null )

getProtocolForTokenizedUrl()

DEPRECATED

Deprecated in 3.0. Use getSchemeForTokenizedUrl() instead.

Returns what the scheme part of the URL should be (http/https) for any tokenized URLs in Craft (email verification links, password reset urls, share entry URLs, etc.

View source

Returns

string

Signature

public static string getProtocolForTokenizedUrl ( )

getSchemeForTokenizedUrl()

Returns what the scheme part of the URL should be (http/https) for any tokenized URLs in Craft (email verification links, password reset urls, share entry URLs, etc.

View source

Returns

string

Signature

public static string getSchemeForTokenizedUrl ( )

host()

Returns the host info for the CP or the current site, depending on the request type.

View source

Returns

string

Throws

Signature

public static string host ( )

hostInfo()

Parses a URL for the host info.

View source

Arguments

Returns

string

Signature

public static string hostInfo ( \craft\helpers\string $url )

isAbsoluteUrl()

Returns whether a given string appears to be an absolute URL.

View source

Arguments

Returns

boolean

Signature

public static boolean isAbsoluteUrl ( \craft\helpers\string $url )

isFullUrl()

Returns whether a given string appears to be a "full" URL (absolute, root-relative or protocol-relative).

View source

Arguments

Returns

boolean

Signature

public static boolean isFullUrl ( \craft\helpers\string $url )

isProtocolRelativeUrl()

Returns whether a given string appears to be a protocol-relative URL.

View source

Arguments

Returns

boolean

Signature

public static boolean isProtocolRelativeUrl ( \craft\helpers\string $url )

isRootRelativeUrl()

Returns whether a given string appears to be a root-relative URL.

View source

Arguments

Returns

boolean

Signature

public static boolean isRootRelativeUrl ( \craft\helpers\string $url )

siteHost()

Returns the current site’s host.

View source

Returns

string

Throws

Signature

public static string siteHost ( )

siteUrl()

Returns a site URL.

View source

Arguments

Returns

string

Throws

Signature

public static string siteUrl ( \craft\helpers\string $path = '', $params = null, \craft\helpers\string $scheme = null, \craft\helpers\int $siteId = null )

stripQueryString()

Removes the query string from a given URL.

View source

Arguments

  • $url (string) – The URL to check.

Returns

string – The URL without a query string.

Signature

public static string stripQueryString ( \craft\helpers\string $url )

url()

Returns either a CP or a site URL, depending on the request type.

View source

Arguments

  • $path (string)
  • $params (array, string, null)
  • $scheme (string, null)
  • $showScriptName (boolean, null) – Whether the script name (index.php) should be included in the URL. By default (null) it will defer to the omitScriptNameInUrls config setting.

Returns

string

Signature

public static string url ( \craft\helpers\string $path = '', $params = null, \craft\helpers\string $scheme = null, \craft\helpers\bool $showScriptName = null )

urlWithParams()

Returns a URL with additional query string parameters.

View source

Arguments

Returns

string

Signature

public static string urlWithParams ( \craft\helpers\string $url, $params )

urlWithProtocol()

DEPRECATED

Deprecated in 3.0. Use urlWithScheme() instead.

Returns a URL with a specific scheme.

View source

Arguments

  • $url (string) – The URL
  • $scheme (string) – The scheme ('http' or 'https')

Returns

string

Signature

public static string urlWithProtocol ( \craft\helpers\string $url, \craft\helpers\string $scheme )

urlWithScheme()

Returns a URL with a specific scheme.

View source

Arguments

  • $url (string) – The URL
  • $scheme (string) – The scheme ('http' or 'https')

Returns

string

Throws

Signature

public static string urlWithScheme ( \craft\helpers\string $url, \craft\helpers\string $scheme )

urlWithToken()

Returns a URL with a 'token' query string param set to a given token.

View source

Arguments

Returns

string

Signature

public static string urlWithToken ( \craft\helpers\string $url, \craft\helpers\string $token )