Craft 3 Class Reference

Class craft\helpers\UrlHelper

Inheritance
craft\helpers\UrlHelper
Available since version
3.0
Source Code
https://github.com/craftcms/cms/blob/master/src/helpers/UrlHelper.php

Class Url

Public Methods
Method Description Defined By
actionUrl() craft\helpers\UrlHelper
baseCpUrl() Returns the Control Panel’s base URL (with a trailing slash) (sans-CP trigger). craft\helpers\UrlHelper
baseRequestUrl() Returns the base URL (with a trailing slash) for the current request. craft\helpers\UrlHelper
baseSiteUrl() Returns the current site’s base URL (with a trailing slash). craft\helpers\UrlHelper
baseUrl() Returns either the current site’s base URL or the CP base URL, depending on the type of request this is. craft\helpers\UrlHelper
cpHost() Returns the Control Panel's host. craft\helpers\UrlHelper
cpUrl() Returns a CP URL. craft\helpers\UrlHelper
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. craft\helpers\UrlHelper
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. craft\helpers\UrlHelper
host() Returns the host info for the CP or the current site, depending on the request type. craft\helpers\UrlHelper
hostInfo() Parses a URL for the host info. craft\helpers\UrlHelper
isAbsoluteUrl() Returns whether a given string appears to be an absolute URL. craft\helpers\UrlHelper
isFullUrl() Returns whether a given string appears to be a "full" URL (absolute, root-relative or protocol-relative). craft\helpers\UrlHelper
isProtocolRelativeUrl() Returns whether a given string appears to be a protocol-relative URL. craft\helpers\UrlHelper
isRootRelativeUrl() Returns whether a given string appears to be a root-relative URL. craft\helpers\UrlHelper
siteHost() Returns the current site’s host. craft\helpers\UrlHelper
siteUrl() Returns a site URL. craft\helpers\UrlHelper
stripQueryString() Removes the query string from a given URL. craft\helpers\UrlHelper
url() Returns either a CP or a site URL, depending on the request type. craft\helpers\UrlHelper
urlWithParams() Returns a URL with additional query string parameters. craft\helpers\UrlHelper
urlWithProtocol() Returns a URL with a specific scheme. craft\helpers\UrlHelper
urlWithScheme() Returns a URL with a specific scheme. craft\helpers\UrlHelper
urlWithToken() Returns a URL with a 'token' query string param set to a given token. craft\helpers\UrlHelper

Method Details

actionUrl() public static method #

public static string actionUrl ( \craft\helpers\string $path '', $params null, \craft\helpers\string $scheme null )
$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.

baseCpUrl() public static method #

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

public static string baseCpUrl ( )

baseRequestUrl() public static method #

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

public static string baseRequestUrl ( )

baseSiteUrl() public static method #

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

public static string baseSiteUrl ( )
throws craft\errors\SiteNotFoundException if there's no current site for some reason

baseUrl() public static method #

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

public static string baseUrl ( )
throws craft\errors\SiteNotFoundException if this is a site request and yet there's no current site for some reason

cpHost() public static method #

Returns the Control Panel's host.

public static string cpHost ( )

cpUrl() public static method #

Returns a CP URL.

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

getProtocolForTokenizedUrl() public static method #

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.

public static string getProtocolForTokenizedUrl ( )

getSchemeForTokenizedUrl() public static method #

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.

public static string getSchemeForTokenizedUrl ( )

host() public static method #

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

public static string host ( )
throws craft\errors\SiteNotFoundException

hostInfo() public static method #

Parses a URL for the host info.

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

isAbsoluteUrl() public static method #

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

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

isFullUrl() public static method #

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

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

isProtocolRelativeUrl() public static method #

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

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

isRootRelativeUrl() public static method #

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

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

siteHost() public static method #

Returns the current site’s host.

public static string siteHost ( )
throws craft\errors\SiteNotFoundException

siteUrl() public static method #

Returns a site URL.

public static string siteUrl ( \craft\helpers\string $path '', $params null, \craft\helpers\string $scheme null, \craft\helpers\int $siteId null )
$path string
$params array, string, null
$scheme string, null
$siteId integer, null
throws yii\base\Exception if|null $siteId is invalid

stripQueryString() public static method #

Removes the query string from a given URL.

public static string stripQueryString ( \craft\helpers\string $url )
$url string The URL to check.
return string The URL without a query string.

url() public static method #

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

public static string url ( \craft\helpers\string $path '', $params null, \craft\helpers\string $scheme null, \craft\helpers\bool $showScriptName null )
$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.

urlWithParams() public static method #

Returns a URL with additional query string parameters.

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

urlWithProtocol() public static method #

Deprecated in 3.0. Use urlWithScheme() instead.

Returns a URL with a specific scheme.

public static string urlWithProtocol ( \craft\helpers\string $url, \craft\helpers\string $scheme )
$url string The URL
$scheme string The scheme ('http' or 'https')

urlWithScheme() public static method #

Returns a URL with a specific scheme.

public static string urlWithScheme ( \craft\helpers\string $url, \craft\helpers\string $scheme )
$url string The URL
$scheme string The scheme ('http' or 'https')
throws craft\errors\SiteNotFoundException

urlWithToken() public static method #

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

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