Contao Utils Bundle

UrlUtil
in package

Table of Contents

Constants

TERMINATE_EXIT_LOCATION_SET  = 900
TERMINATE_HEADERS_ALREADY_SENT  = 800

Properties

$framework  : ContaoFrameworkInterface
$requestStack  : RequestStack
$requestUtil  : RequestUtil

Methods

__construct()  : mixed
addAutoItemToPage()  : mixed
addQueryString()  : string
Add a query string to the given URI string or page ID.
addURIScheme()  : string
Add a url scheme to a given url.
getBaseUrl()  : mixed
getCurrentUrl()  : string
Return the current url with requestUri.
getJumpToPageObject()  : PageModel|null
getJumpToPageUrl()  : string|null
getRelativePath()  : string
Convert an absolute url to an relative url.
isNewVisitor()  : bool
Detect if user already visited our domain before.
prepareUrl()  : string
Prepare URL from ID and keep query string from current string.
redirect()  : int|array<string|int, mixed>|null
Redirect to another page.
removeQueryString()  : string
Remove query parameters from the current URL.

Constants

TERMINATE_EXIT_LOCATION_SET

public mixed TERMINATE_EXIT_LOCATION_SET = 900

TERMINATE_HEADERS_ALREADY_SENT

public mixed TERMINATE_HEADERS_ALREADY_SENT = 800

Properties

$framework

protected ContaoFrameworkInterface $framework

$requestStack

private RequestStack $requestStack

Methods

__construct()

public __construct(ContaoFrameworkInterface $framework, RequestUtil $requestUtil, RequestStack $requestStack) : mixed
Parameters
$framework : ContaoFrameworkInterface
$requestUtil : RequestUtil
$requestStack : RequestStack

addAutoItemToPage()

public static addAutoItemToPage(Model $page, Model $entity[, mixed $autoItemType = 'items' ]) : mixed
Parameters
$page : Model
$entity : Model
$autoItemType : mixed = 'items'

addQueryString()

Add a query string to the given URI string or page ID.

public addQueryString(string $query[, mixed $url = null ]) : string

Use Utils service instead

Parameters
$query : string
$url : mixed = null
Tags
throws
InvalidArgumentException
codeCoverageIgnore
Return values
string

addURIScheme()

Add a url scheme to a given url.

public addURIScheme([string $url = '' ][, string $protocol = 'http' ]) : string
Parameters
$url : string = ''
$protocol : string = 'http'
Return values
string

getBaseUrl()

public getBaseUrl([bool $absolute = false ]) : mixed

Use Utils::request() instead

Parameters
$absolute : bool = false

getCurrentUrl()

Return the current url with requestUri.

public getCurrentUrl([array<string|int, mixed> $options = [] ]) : string

Options:

  • skipParams: boolean
Parameters
$options : array<string|int, mixed> = []
Return values
string

getJumpToPageObject()

public getJumpToPageObject(int $jumpTo[, bool $fallbackToObjPage = true ]) : PageModel|null
Parameters
$jumpTo : int
$fallbackToObjPage : bool = true
Return values
PageModel|null

getJumpToPageUrl()

public getJumpToPageUrl(int $jumpTo[, bool $fallbackToObjPage = true ]) : string|null
Parameters
$jumpTo : int
$fallbackToObjPage : bool = true
Return values
string|null

getRelativePath()

Convert an absolute url to an relative url.

public getRelativePath(string $url[, array<string|int, mixed> $options = [] ]) : string

Options:

  • removeLeadingSlash: (boolean) Remove a
Parameters
$url : string

The url that should be made relative

$options : array<string|int, mixed> = []

Pass additional options

Tags
throws
InvalidUrlException
Return values
string

isNewVisitor()

Detect if user already visited our domain before.

public isNewVisitor() : bool

please use RequestUtil::isNewVisitor() instead

Tags
codeCoverageIgnore
Return values
bool

prepareUrl()

Prepare URL from ID and keep query string from current string.

public prepareUrl([mixed $url = null ][, array<string|int, mixed> $options = [] ]) : string

Options:

  • absoluteUrl: (boolean) Return absolute url instead of relative url. Only applicable if id or null is given as url. Default: false
Parameters
$url : mixed = null
$options : array<string|int, mixed> = []

pass additional options

Tags
codeCoverageIgnore
Return values
string

redirect()

Redirect to another page.

public redirect(string $strLocation[, int $intStatus = 303 ][, bool $test = false ][, bool $skipSent = false ]) : int|array<string|int, mixed>|null
Parameters
$strLocation : string

The target URL

$intStatus : int = 303

The HTTP status code (defaults to 303)

$test : bool = false

For test purposes set to true to test exit/headers

$skipSent : bool = false

Skip if headers already sent for test purposes

Return values
int|array<string|int, mixed>|null

removeQueryString()

Remove query parameters from the current URL.

public removeQueryString(array<string|int, mixed> $params[, string|int|null $url = null ][, array<string|int, mixed> $options = [] ]) : string

Use utils service instead

Options:

  • absoluteUrl: (boolean) Return absolute url instead of relative url. Only applicable if id or null is given as url. Default: false
Parameters
$params : array<string|int, mixed>

List of parameters to remove from url

$url : string|int|null = null

Full Uri, Page id or null (for current environment uri)

$options : array<string|int, mixed> = []
Tags
codeCoverageIgnore
Return values
string

        
On this page

Search results