2016-09-19 95 views
0

我有一個擴展名,當我把這個擴展與沒有或不再存在,我得到一個異常Object of type My\Model\... with identity "1035" not found.extbase重定向到404默認

頁記錄的ID本身得到了標題狀態500.

我想在這種情況下做的是顯示我的默認404頁面。這可能嗎?我該怎麼做?

回答

1

我猜你正在使用的方法類似

public function detailAction(\YourVendor\Ext\Domain\Model\MyModel $model) 

在這種情況下,由於異常在extbase的核心已經拋出它不是那麼容易的。你可以看看我是如何解決這個問題對我news extension

/** 
    * @param RequestInterface $request 
    * @param ResponseInterface $response 
    * @throws \Exception 
    */ 
    public function processRequest(RequestInterface $request, ResponseInterface $response) 
    { 
     try { 
      parent::processRequest($request, $response); 
     } catch (\Exception $exception) { 
      $this->handleKnownExceptionsElseThrowAgain($exception); 
     } 
    } 
    /** 
    * @param \Exception $exception 
    * @throws \Exception 
    */ 
    private function handleKnownExceptionsElseThrowAgain(\Exception $exception) 
    { 
     $previousException = $exception->getPrevious(); 
     if (
      $this->actionMethodName === 'detailAction' 
      && $previousException instanceof \TYPO3\CMS\Extbase\Property\Exception 
      && isset($this->settings['detail']['errorHandling']) 
     ) { 
      $this->handleNoNewsFoundError($this->settings['detail']['errorHandling']); 
     } else { 
      throw $exception; 
     } 
    } 

在該方法中handleNoNewsFoundError你能做到,那麼你想,例如什麼調用$GLOBALS['TSFE']->pageNotFoundAndExit('No news entry found.');

+1

恰恰我使用了使用擴展生成器創建的默認'showAction'。您的解決方案完美運作對於其他人:您必須聲明名稱空間或使用processRequest函數變量中的完整路徑。 – nbar

0

未經測試,但從邏輯POV你應該趕上例外,然後讓你的控制器決定做什麼(在你的情況下:顯示404頁)。