Contao Utils Bundle

UrlUtil
in package

Table of Contents

Properties

$requestStack  : RequestStack

Methods

__construct()  : mixed
addQueryStringParameterToUrl()  : string
Add a query string parameter to a URL.
makeUrlRelative()  : string
Convert an absolute url to a relative url.
removeQueryStringParameterFromUrl()  : string
Remove query parameters (GET parameter) from a URL.
buildUrlString()  : string

Properties

$requestStack read-only

private RequestStack $requestStack

Methods

__construct()

public __construct(RequestStack $requestStack) : mixed
Parameters
$requestStack : RequestStack

addQueryStringParameterToUrl()

Add a query string parameter to a URL.

public addQueryStringParameterToUrl(string|array<string, string> $parameter[, string $url = '' ]) : string

You can pass a string or an associative array to $parameter. If no url is given, the current request URL is used.

Parameters
$parameter : string|array<string, string>

The query parameters to add.

$url : string = ''

The URL to which query parameter should be added.

Tags
example

addQueryStringParameterToUrl('foo=bar', 'https://example.com') // https://example.com?foo=bar

example

addQueryStringParameterToUrl(['foo' => 'bar'], 'https://example.com') // https://example.com?foo=bar

Return values
string

The concatenated URL.

makeUrlRelative()

Convert an absolute url to a relative url.

public makeUrlRelative(string $url[, array{removeLeadingSlash?: bool} $options = [] ]) : string

Options:

  • removeLeadingSlash: Remove leading slash from path
Parameters
$url : string

The url that should be made relative

$options : array{removeLeadingSlash?: bool} = []

Pass additional options

Tags
throws
InvalidUrlException
Return values
string

removeQueryStringParameterFromUrl()

Remove query parameters (GET parameter) from a URL.

public removeQueryStringParameterFromUrl(string|array<string|int, string> $parameter[, string $url = '' ]) : string

You can pass a string or an associative array to $parameter. If no URL is given, the current request url is used.

Parameters
$parameter : string|array<string|int, string>

The query parameter names to remove.

$url : string = ''

The URL to rid of the given query parameters.

Tags
example

removeQueryStringParameterFromUrl('foo', 'https://example.com?foo=bar&baz=fuzz') // https://example.com?baz=fuzz

example

removeQueryStringParameterFromUrl(['foo', 'baz'], 'https://example.com?foo=bar&baz=fuzz') // https://example.com

Return values
string

The URL without the given query parameters.

buildUrlString()

private buildUrlString(array<string|int, mixed> $parsedUrl) : string
Parameters
$parsedUrl : array<string|int, mixed>
Return values
string

        
On this page

Search results