How to get uri of current page in extbase extension controller? In case I need to send current uri via email or save it to database for later use or statistics.
Asked
Active
Viewed 1.4k times
2 Answers
13
You can use this line:
$this->uriBuilder->getRequest()->getRequestUri()
Example:
public function newAction(Tx_YourExtension_Domain_Model_YourModel $yourModel = NULL) {
$this->view->assign('yourModel', $yourModel);
$this->view->assign('url', $this->uriBuilder->getRequest()->getRequestUri());
}

gSorry
- 1,254
- 2
- 21
- 29
6
Though following is more efficient..
$this->controllerContext
->getUriBuilder()
->reset()
->setTargetPageUid(int PAGE_UID)
->setArguments(array ARRAY_VARIABLE_OF_ADDITIONAL_ARGUMENTS)
->buildFrontendUri();
OR
Include UriBuilder object
/**
* UriBuilder
*
* @var \TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
* @inject
*/
protected $uriBuilder = NULL;
Get URL using following
$this->uriBuilder
->reset()
->setTargetPageUid(int PAGE_UID)
->setArguments(array ARRAY_VARIABLE_OF_ADDITIONAL_ARGUMENTS)
->buildFrontendUri();
For Base Uri
$this->request->getBaseUri()
OR
$GLOBALS['TSFE']->baseUrl

Mihir Bhatt
- 3,019
- 2
- 37
- 41
-
This one helped me a lot.!! Thanks Mihir – Maulik Bhojani Jul 29 '14 at 09:06
-
1I don't see how this is more efficient. – j4k3 Apr 14 '15 at 12:19