UrlHelper

Type
Class
Namespace
Craft
Inherits
Craft\UrlHelper
Since
1.0

Class UrlHelper

See also http://craftcms.com

View source

# Public Methods

Method Description
getActionUrl()
getCpUrl() Returns a CP URL.
getProtocolForTokenizedUrl() Returns what the protocol/schema part of the URL should be (http/https) for any tokenized URLs in Craft (email verification links, password reset urls, share entry URLs, etc.
getResourceUrl() Returns a resource URL.
getSiteUrl() Returns a site URL.
getUrl() Returns either a CP or a site URL, depending on the request type.
getUrlWithParams() Returns a URL with additional query string parameters.
getUrlWithProtocol() Returns a URL with a specific protocol.
getUrlWithToken() Returns a URL with a 'token' query string param set to a given token.
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.
stripQueryString() Removes the query string from a given URL.

# getActionUrl()

View source

Arguments

  • $path (string)
  • $params (null)
  • $protocol (string) – The protocol to use (e.g. http, https). If empty, the protocol used for the current request will be used.

Returns

array, string

Signature

public static array, string getActionUrl ( $path = '', $params = null, $protocol = null )

# getCpUrl()

Returns a CP URL.

View source

Arguments

Returns

string

Signature

public static string getCpUrl ( $path = '', $params = null, $protocol = null )

# getProtocolForTokenizedUrl()

Returns what the protocol/schema 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 ( )

# getResourceUrl()

Returns a resource URL.

View source

Arguments

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

Returns

string

Signature

public static string getResourceUrl ( $path = '', $params = null, $protocol = null )

# getSiteUrl()

Returns a site URL.

View source

Arguments

Returns

string

Signature

public static string getSiteUrl ( $path = '', $params = null, $protocol = null, $localeId = null )

# getUrl()

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

View source

Arguments

Returns

string

Signature

public static string getUrl ( $path = '', $params = null, $protocol = null, $mustShowScriptName = false )

# getUrlWithParams()

Returns a URL with additional query string parameters.

View source

Arguments

Returns

string

Signature

public static string getUrlWithParams ( $url, $params )

# getUrlWithProtocol()

Returns a URL with a specific protocol.

View source

Arguments

Returns

string

Signature

public static string getUrlWithProtocol ( $url, $protocol )

# getUrlWithToken()

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

View source

Arguments

Returns

string

Signature

public static string getUrlWithToken ( $url, $token )

# isAbsoluteUrl()

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

View source

Arguments

Returns

boolean

Signature

public static boolean isAbsoluteUrl ( $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 ( $url )

# isProtocolRelativeUrl()

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

View source

Arguments

Returns

boolean

Signature

public static boolean isProtocolRelativeUrl ( $url )

# isRootRelativeUrl()

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

View source

Arguments

Returns

boolean

Signature

public static boolean isRootRelativeUrl ( $url )

# stripQueryString()

Removes the query string from a given URL.

View source

Arguments

  • $url – The URL to check.

Returns

string – The URL without a query string.

Signature

public static string stripQueryString ( $url )