UrlHelper ​
- Type
- Class
- Namespace
- craft\helpers
- Inherits
- craft\helpers\UrlHelper
- Since
- 3.0.0
Class Url
Public Methods ​
Method | Description |
---|---|
actionUrl() | |
baseCpUrl() | Returns the control panel’s base URL (with a trailing slash) (sans control panel trigger). |
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 param values, except for / , { , and } characters. |
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 control panel 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. |
urlWithScheme() | Returns a URL with a specific scheme. |
urlWithToken() | Returns a URL with a 'token' query string param set to a given token. |
actionUrl()
​
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.$showScriptName
(boolean) – Whether the script name (index.php) should be included in the URL. Note that it’s only safe to set this tofalse
for URLs that will be used for GET requests.
Returns ​
baseCpUrl()
​
Returns the control panel’s base URL (with a trailing slash) (sans control panel trigger).
Returns ​
baseSiteUrl()
​
Returns the current site’s base URL (with a trailing slash).
Returns ​
Throws ​
- craft\errors\SiteNotFoundException
if there's no current site for some reason
baseUrl()
​
Returns either the current site’s base URL or the control panel’s base URL, depending on the type of request this is.
Returns ​
Throws ​
- craft\errors\SiteNotFoundException
if this is a site request and yet there's no current site for some reason
buildQuery()
​
- Since
- 3.3.0
Returns a query string based on the given params.
Param values will be encoded, except for /
, {
, and }
characters.
Arguments ​
$params
(array)
Returns ​
cpHost()
​
Returns the control panel's host.
Returns ​
cpUrl()
​
Returns a control panel URL.
Arguments ​
Returns ​
encodeParams()
​
- Since
- 3.7.24
Encodes a URL’s query string param values, except for /
, {
, and }
characters.
Arguments ​
$url
(string)
Returns ​
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.
Arguments ​
$cp
(boolean) – Whether this is for a control panel URL
Returns ​
host()
​
Returns the host info for the control panel or the current site, depending on the request type.
Returns ​
Throws ​
hostInfo()
​
Parses a URL for the host info.
Arguments ​
$url
(string)
Returns ​
isAbsoluteUrl()
​
Returns whether a given string appears to be an absolute URL.
Arguments ​
$url
(string)
Returns ​
isFullUrl()
​
Returns whether a given string appears to be a "full" URL (absolute, root-relative or protocol-relative).
Arguments ​
$url
(string)
Returns ​
isProtocolRelativeUrl()
​
Returns whether a given string appears to be a protocol-relative URL.
Arguments ​
$url
(string)
Returns ​
isRootRelativeUrl()
​
Returns whether a given string appears to be a root-relative URL.
Arguments ​
$url
(string)
Returns ​
prependCpTrigger()
​
- Since
- 3.5.0
Prepends the control panel trigger onto the given path.
Arguments ​
$path
(string)
Returns ​
removeParam()
​
- Since
- 3.2.2
Removes a query string param from a URL.
Arguments ​
Returns ​
rootRelativeUrl()
​
- Since
- 3.1.11
Returns a root-relative URL based on the given URL.
Arguments ​
$url
(string)
Returns ​
siteHost()
​
Returns the current site’s host.
Returns ​
Throws ​
siteUrl()
​
Returns a site URL.
Arguments ​
Returns ​
Throws ​
- yii\base\Exception
if|null $siteId is invalid
stripQueryString()
​
Removes the query string from a given URL.
Arguments ​
$url
(string) – The URL to check.
Returns ​
string – The URL without a query string.
url()
​
Returns either a control panel or a site URL, depending on the request type.
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 theomitScriptNameInUrls
config setting.
Returns ​
urlWithParams()
​
Returns a URL with additional query string parameters.
Arguments ​
Returns ​
urlWithScheme()
​
Returns a URL with a specific scheme.
Arguments ​
Returns ​
Throws ​
urlWithToken()
​
Returns a URL with a 'token' query string param set to a given token.