EXTBASE:如何在extbase控制器中获取当前页面uri?

时间:2013-07-30 15:43:37

标签: controller request uri extbase uribuilder

如何在extbase扩展控制器中获取当前页面的uri?如果我需要通过电子邮件发送当前的uri或将其保存到数据库供以后使用或统计。

2 个答案:

答案 0 :(得分:8)

您可以使用以下行:

$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());
}

答案 1 :(得分:5)

虽然以下效率更高..

 $this->controllerContext
  ->getUriBuilder()
  ->reset()
  ->setTargetPageUid(int PAGE_UID)
  ->setArguments(array ARRAY_VARIABLE_OF_ADDITIONAL_ARGUMENTS)
  ->buildFrontendUri();

OR

包含UriBuilder对象

/**
 * UriBuilder
 *
 * @var \TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
 * @inject
 */
protected $uriBuilder = NULL;

使用以下

获取网址
$this->uriBuilder
    ->reset()
    ->setTargetPageUid(int PAGE_UID)
    ->setArguments(array ARRAY_VARIABLE_OF_ADDITIONAL_ARGUMENTS)
    ->buildFrontendUri();

对于Base Uri

$this->request->getBaseUri()
     OR
$GLOBALS['TSFE']->baseUrl