Posted at

【Drupal8】現在のURLパスを取得する

More than 1 year has passed since last update.

メモ:URLパスを取得する方法


現在のURLパスを取得する

$request = \Drupal::request();

$request->getRequestUri();

or

\Drupal::request()->getRequestUri();


他にホスト名ポート情報の取得などが可能です。

以下、提供されているメソッド一覧

    [0] => __construct

[1] => initialize
[2] => createFromGlobals
[3] => create
[4] => setFactory
[5] => duplicate
[6] => __clone
[7] => __toString
[8] => overrideGlobals
[9] => setTrustedProxies
[10] => getTrustedProxies
[11] => setTrustedHosts
[12] => getTrustedHosts
[13] => setTrustedHeaderName
[14] => getTrustedHeaderName
[15] => normalizeQueryString
[16] => enableHttpMethodParameterOverride
[17] => getHttpMethodParameterOverride
[18] => get
[19] => getSession
[20] => hasPreviousSession
[21] => hasSession
[22] => setSession
[23] => getClientIps
[24] => getClientIp
[25] => getScriptName
[26] => getPathInfo
[27] => getBasePath
[28] => getBaseUrl
[29] => getScheme
[30] => getPort
[31] => getUser
[32] => getPassword
[33] => getUserInfo
[34] => getHttpHost
[35] => getRequestUri
[36] => getSchemeAndHttpHost
[37] => getUri
[38] => getUriForPath
[39] => getRelativeUriForPath
[40] => getQueryString
[41] => isSecure
[42] => getHost
[43] => setMethod
[44] => getMethod
[45] => getRealMethod
[46] => getMimeType
[47] => getFormat
[48] => setFormat
[49] => getRequestFormat
[50] => setRequestFormat
[51] => getContentType
[52] => setDefaultLocale
[53] => getDefaultLocale
[54] => setLocale (link is external)
[55] => getLocale
[56] => isMethod
[57] => isMethodSafe
[58] => getContent
[59] => getETags
[60] => isNoCache
[61] => getPreferredLanguage
[62] => getLanguages
[63] => getCharsets
[64] => getEncodings
[65] => getAcceptableContentTypes
[66] => isXmlHttpRequest