Attention
TYPO3 v11 has reached end-of-life as of October 31th 2024 and is no longer being maintained. Use the version switcher on the top left of this page to select documentation for a supported version of TYPO3.
Need more time before upgrading? You can purchase Extended Long Term Support (ELTS) for TYPO3 v11 here: TYPO3 ELTS.
URI builder (Extbase)
The URI builder offers a convenient way to create links in an Extbase context.
Usage in an Extbase controller
The URI builder is available as a property in a controller class which extends the ActionController class.
Example:
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\Controller\MyController;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
final class MyController extends ActionController
{
public function myAction(): ResponseInterface
{
$url = $this->uriBuilder
->reset()
->setTargetPageUid(42)
->uriFor(
'anotherAction',
[
'myRecord' => 21,
],
'MyController',
'myextension',
'myplugin'
);
// do something with $url
}
}
Have a look into the API for the available methods of the URI builder.
Attention
As the URI builder holds state, you have to call
reset before
creating a URL.
Usage in another context
The
\TYPO3\ class can be injected
via constructor in a class:
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\MyClass;
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
final class MyClass
{
private UriBuilder $uriBuilder;
public function __construct(UriBuilder $uriBuilder)
{
$this->uriBuilder = $uriBuilder;
}
public function doSomething()
{
$url = $this->uriBuilder
->reset()
->setTargetPageUid(42)
->uriFor(
'myAction',
[
'myRecord' => 21,
],
'MyController',
'myextension',
'myplugin'
);
// do something with $url
}
}
API
-
class
UriBuilder -
- Fully qualified name
-
\TYPO3\CMS\ Extbase\ Mvc\ Web\ Routing\ Uri Builder
An URI Builder
setArguments(array $arguments)-
Additional query parameters.
If you want to "prefix" arguments, you can pass in multidimensional arrays: array('prefix1' => array('foo' => 'bar')) gets "&prefix1[foo]=bar"
- param array $arguments
-
the arguments
- returntype
-
TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
- Returns
-
the current UriBuilder to allow method chaining
setSection(string $section)-
If specified, adds a given HTML anchor to the URI (#...)
- param string $section
-
the section
- returntype
-
TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
- Returns
-
the current UriBuilder to allow method chaining
setFormat(string $format)-
Specifies the format of the target (e.g. "html" or "xml")
- param string $format
-
the format
- returntype
-
TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
- Returns
-
the current UriBuilder to allow method chaining
setCreateAbsoluteUri(bool $createAbsoluteUri)-
If set, the URI is prepended with the current base URI. Defaults to FALSE.
- param bool $createAbsoluteUri
-
the createAbsoluteUri
- returntype
-
TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
- Returns
-
the current UriBuilder to allow method chaining
setAbsoluteUriScheme(string $absoluteUriScheme)-
Sets the scheme that should be used for absolute URIs in FE mode
- param string $absoluteUriScheme
-
the scheme to be used for absolute URIs
- returntype
-
TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
- Returns
-
the current UriBuilder to allow method chaining
setLanguage(string $language)-
Enforces a URI / link to a page to a specific language (or use "current")
- param string $language
-
the language
- returntype
-
TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
setAddQueryString(bool $addQueryString)-
If set, the current query parameters will be merged with $this->arguments. Defaults to FALSE.
- param bool $addQueryString
-
the addQueryString
- returntype
-
TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
- Returns
-
the current UriBuilder to allow method chaining
setArgumentsToBeExcludedFromQueryString(array $argumentsToBeExcludedFromQueryString)-
A list of arguments to be excluded from the query parameters Only active if addQueryString is set
- param array $argumentsToBeExcludedFromQueryString
-
the argumentsToBeExcludedFromQueryString
- returntype
-
TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
- Returns
-
the current UriBuilder to allow method chaining
setArgumentPrefix(string $argumentPrefix)-
Specifies the prefix to be used for all arguments.
- param string $argumentPrefix
-
the argumentPrefix
- returntype
-
TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
- Returns
-
the current UriBuilder to allow method chaining
setLinkAccessRestrictedPages(bool $linkAccessRestrictedPages)-
If set, URIs for pages without access permissions will be created
- param bool $linkAccessRestrictedPages
-
the linkAccessRestrictedPages
- returntype
-
TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
- Returns
-
the current UriBuilder to allow method chaining
setTargetPageUid(int $targetPageUid)-
Uid of the target page
- param int $targetPageUid
-
the targetPageUid
- returntype
-
TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
- Returns
-
the current UriBuilder to allow method chaining
setTargetPageType(int $targetPageType)-
Sets the page type of the target URI. Defaults to 0
- param int $targetPageType
-
the targetPageType
- returntype
-
TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
- Returns
-
the current UriBuilder to allow method chaining
setNoCache(bool $noCache)-
by default FALSE; if TRUE, &no_cache=1 will be appended to the URI
- param bool $noCache
-
the noCache
- returntype
-
TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
- Returns
-
the current UriBuilder to allow method chaining
reset()-
Resets all UriBuilder options to their default value
- returntype
-
TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
- Returns
-
the current UriBuilder to allow method chaining
uriFor(string $actionName = NULL, array $controllerArguments = NULL, string $controllerName = NULL, string $extensionName = NULL, string $pluginName = NULL)-
Creates an URI used for linking to an Extbase action.
Works in Frontend and Backend mode of TYPO3.
- param string $actionName
-
Name of the action to be called, default: NULL
- param array $controllerArguments
-
Additional query parameters. Will be "namespaced" and merged with $this->arguments., default: NULL
- param string $controllerName
-
Name of the target controller. If not set, current ControllerName is used., default: NULL
- param string $extensionName
-
Name of the target extension, without underscores. If not set, current ExtensionName is used., default: NULL
- param string $pluginName
-
Name of the target plugin. If not set, current PluginName is used., default: NULL
- returntype
-
string
- Returns
-
the rendered URI