How to create an internal URI in TYPO3
Sometimes you want to generate TYPO3 internal URIs programmatically. Now you could try to create the URL manually on your own, or use the UriBuilder
class. This handy tool is pretty neat to create any kind of internal URI. In a controller this class is available by $this->getControllerContext()->getUriBuilder()
. If you want to use the UriBuilder
somewhere else, you need to load an instance of the class by the ObjectManager
.
$objectManager =
GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager\ObjectManager::class);
$uriBuilder =
$objectManager->get(\TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder::class);
When you have access to an instance of the builder, it's pretty straight forward from now on. The class has a bunch of simple setters, to control the generation of the URI. Best practice is to reset
all the options of the builder on start of every new URI creation.
Kommentar