簡體   English   中英

TYPO3 Extbase - 重定向到 pid

[英]TYPO3 Extbase - redirect to pid

$GLOBALS['TSFE']->pageNotFoundAndExit('');

當前正在使用,但我想重定向到頁面 ID。

使用命令redirectToUri ,我找不到解決方案,或者沒有工作。

代碼:

/**
* initialize action show
* @return void
*/
public function initializeShowAction() {
  if ($this->request->hasArgument('xxx')) {
    if ( $xxx=$this->xxxRepository->findByUid(
      intval($this->request->getArgument('xxx'))
    ) ) {
      $this->request->setArgument('xxx',$xxx);
      return;
    }
  }

$GLOBALS['TSFE']->pageNotFoundAndExit('');

}

您可以在控制器中使用以下代碼構建 uri:

$uriBuilder = $this->uriBuilder;
$uri = $uriBuilder
  ->setTargetPageUid($pageUid)
  ->build();
$this->redirectToUri($uri, 0, 404);

在您的控制器中,您可以使用以下選項之一:

# Internal redirect of request to another controller
$this->forward($actionName, $controllerName, $extensionName, array $arguments);

# External HTTP redirect to another controller
$this->redirect($actionName, $controllerName, $extensionName, array $arguments, $pageUid, $delay = 0, $statusCode = 303);

# Redirect to URI
$this->redirectToURI($uri, $delay=0, $statusCode=303);

# Send HTTP status code
$this->throwStatus($statusCode, $statusMessage, $content);

謝謝大家。 我現在的解決辦法是:

$pageUid = $this->settings['myflexformsettingpart'];
$uriBuilder = $this->uriBuilder;
$uri = $uriBuilder
  ->setTargetPageUid($pageUid)
  ->build();
$this->redirectToURI($uri, $delay=0, $statusCode=303);

我像這樣使用它:

$GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling'] = '/my/404/';

請注意,我使用了 realURL 生成的 URL。

您還可以使用控制器的重定向功能。 像:

    if(!$pageUid = intval($this->settings['resultPageUid']))
    {
        $pageUid = $GLOBALS['TSFE']->id;
    }
    $this->redirect(null, null, null, null, $pageUid);

因此,如果在您的設置中找不到要重定向到的頁面 uid,或者找到的 uid 不是整數,它將被重定向到當前頁面 uid。

重定向函數允許另外兩個參數:

  • 延遲,整數,默認 0
  • 狀態碼,整數,默認 303

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM