UrlHelper

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

Class Url

View source (opens new window)

# Public Methods

Method Description
actionUrl()
baseCpUrl() Returns the control panel’s base URL (with a trailing slash) (sans control panel 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 control panel’s base URL, depending on the type of request this is.
buildQuery() Returns a query string based on the given params.
cpHost() Returns the control panel's host.
cpUrl() Returns a control panel URL.
encodeParams() Encodes a URL’s query string params.
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 control panel 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.
prependCpTrigger() Prepends the CP trigger onto the given path.
removeParam() Removes a query string param from a URL.
rootRelativeUrl() Returns a root-relative URL based on the given 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 control panel 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 (opens new window)

Arguments

Returns

string (opens new window)

# baseCpUrl()

Returns the control panel’s base URL (with a trailing slash) (sans control panel trigger).

View source (opens new window)

Returns

string (opens new window)

# baseRequestUrl()

DEPRECATED

Deprecated in 3.7.15. Craft::getAlias('@web') should be used instead.

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

View source (opens new window)

Returns

string (opens new window)

# baseSiteUrl()

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

View source (opens new window)

Returns

string (opens new window)

Throws

# baseUrl()

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

View source (opens new window)

Returns

string (opens new window)

Throws

# buildQuery()

Since
3.3.0

Returns a query string based on the given params.

View source (opens new window)

Arguments

Returns

string (opens new window)

# cpHost()

Returns the control panel's host.

View source (opens new window)

Returns

string (opens new window)

# cpUrl()

Returns a control panel URL.

View source (opens new window)

Arguments

Returns

string (opens new window)

# encodeParams()

Since
3.7.24

Encodes a URL’s query string params.

View source (opens new window)

Arguments

Returns

string (opens new window)

# getProtocolForTokenizedUrl()

DEPRECATED

Deprecated in 3.0.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 (opens new window)

Returns

string (opens new window)

# 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 (opens new window)

Arguments

Returns

string (opens new window)

# host()

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

View source (opens new window)

Returns

string (opens new window)

Throws

# hostInfo()

Parses a URL for the host info.

View source (opens new window)

Arguments

Returns

string (opens new window)

# isAbsoluteUrl()

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

View source (opens new window)

Arguments

Returns

boolean (opens new window)

# isFullUrl()

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

View source (opens new window)

Arguments

Returns

boolean (opens new window)

# isProtocolRelativeUrl()

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

View source (opens new window)

Arguments

Returns

boolean (opens new window)

# isRootRelativeUrl()

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

View source (opens new window)

Arguments

Returns

boolean (opens new window)

# prependCpTrigger()

Since
3.5.0

Prepends the CP trigger onto the given path.

View source (opens new window)

Arguments

Returns

string (opens new window)

# removeParam()

Since
3.2.2

Removes a query string param from a URL.

View source (opens new window)

Arguments

Returns

string (opens new window)

# rootRelativeUrl()

Since
3.1.11

Returns a root-relative URL based on the given URL.

View source (opens new window)

Arguments

Returns

string (opens new window)

# siteHost()

Returns the current site’s host.

View source (opens new window)

Returns

string (opens new window)

Throws

# siteUrl()

Returns a site URL.

View source (opens new window)

Arguments

Returns

string (opens new window)

Throws

# stripQueryString()

Removes the query string from a given URL.

View source (opens new window)

Arguments

Returns

string (opens new window) – The URL without a query string.

# url()

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

View source (opens new window)

Arguments

Returns

string (opens new window)

# urlWithParams()

Returns a URL with additional query string parameters.

View source (opens new window)

Arguments

Returns

string (opens new window)

# urlWithProtocol()

DEPRECATED

Deprecated in 3.0.0. Use urlWithScheme() instead.

Returns a URL with a specific scheme.

View source (opens new window)

Arguments

Returns

string (opens new window)

# urlWithScheme()

Returns a URL with a specific scheme.

View source (opens new window)

Arguments

Returns

string (opens new window)

Throws

# urlWithToken()

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

View source (opens new window)

Arguments

Returns

string (opens new window)