如何在 Extbase 扩展控制器中获取当前页面的 URI?如果我需要通过电子邮件发送当前 URI 或将其保存到数据库以供以后使用或统计怎么办?
您可以使用这行代码:
$this->uriBuilder->getRequest()->getRequestUri()
例子:
public function newAction(Tx_YourExtension_Domain_Model_YourModel $yourModel = NULL) {
$this->view->assign('yourModel', $yourModel);
$this->view->assign('url', $this->uriBuilder->getRequest()->getRequestUri());
}
$this->controllerContext
->getUriBuilder()
->reset()
->setTargetPageUid(int PAGE_UID)
->setArguments(array ARRAY_VARIABLE_OF_ADDITIONAL_ARGUMENTS)
->buildFrontendUri();
或者
包括UriBuilder对象
/**
* UriBuilder
*
* @var \TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
* @inject
*/
protected $uriBuilder = NULL;
使用以下方式获取URL
$this->uriBuilder
->reset()
->setTargetPageUid(int PAGE_UID)
->setArguments(array ARRAY_VARIABLE_OF_ADDITIONAL_ARGUMENTS)
->buildFrontendUri();
关于基本URI
$this->request->getBaseUri()
OR
$GLOBALS['TSFE']->baseUrl