2016-06-10 45 views
0

當我嘗試在開發環境中拋出一個簡單的throw $this->NotFoundHttpException('We do not currently have a website configured at this address. Please visit our website for more information or contact our support team');時,它工作正常。但是當我在產品環境中做同樣的事情時,我得到500個服務器錯誤。 enter image description here在產品環境中無法顯示404錯誤

任何想法?

這裏是我的dev和督促日誌文件

enter image description here

enter image description here

注截圖:500錯誤只有當我在督促ENV URL中使用www發生。在使用任何其他詞例如。 nike,這就是我得到 enter image description here

下面是正常www.blore.eduflats.com網址 enter image description here

+0

您的日誌文件中的任何消息? – MrWillihog

+0

我剛剛發佈了他們 – utkarsh2k2

+0

不知道如何理解'em – utkarsh2k2

回答

2

爲了從你的控制器返回404按照symfony documentation你需要做以下的開發ENV結果:

throw $this->createNotFoundException('The product does not exist'); 

然而,你有

throw $this->NotFoundHttpException 

您看到的錯誤告訴您,NotFoundHttpException不存在。要解決你的問題簡單地createNotFoundException

+0

我剛試過'throw $ this-> createNotFoundException('產品不存在');'結果相同 – utkarsh2k2

+0

道歉,我誤讀了你說的那部分在開發中工作。在這種情況下,我會刪除這個答案。但首先你應該檢查你是否在開發和生產中運行相同版本的symfony。 – MrWillihog

+0

答案其實非常接近。 createNotfoundException()方法在基礎控制器類中定義,這就是爲什麼它不在你的類中。嘗試:拋出新的NotFoundHttpException($ message);至於生產與發展?一個神祕的東西,但發展有額外的聽衆,這可能會阻止你的聽衆接收事件。 – Cerad

0

你叫Eduflas.. UniversityResolver->NotFoundHttpException(); 如果你想trhow這樣的例外替換NotFoundHttpException,你應該申報。 Symfony的控制器具有$this->createNotFoundException('Something Not found'); 你可以拋出404這樣的:

use Symfony\Component\HttpKernel\Exception\NotFoundHttpException 
//... 
throw new NotFoundHttpException("Not found"); 

用這種方式來確保異常存在,並對其進行測試。 無論如何清除您的產品和dev 緩存以確保您使用「相同的代碼」。 最後一件事情來到我的頭上 - 它可能會覆蓋錯誤頁面,並且您可能會對error.html.twig或error404.html.twig做出一些改動,並且會得到不同的頁面。


EDIT 當我輸入您http://blore.eduflats.com/我得到

「陣列(29){[」 HTTP_HOST 「] =>串(18) 」blore.eduflats.com「[」 HTTP_USER_AGENT」 ] => s ...「

無論如何,你的開發環境。也有錯誤,所以如何在prod env上工作... 如果你在開發中拋出NotFoundException,你應該得到symfony調試器頁面和這個錯誤。在產品中,這個錯誤是ExceptionController捕獲並顯示空白錯誤頁面(用戶不應該看到異常,只有500錯誤)

+0

爲了避免這種不幸,實際上我插入了'throw new createNotFoundException('產品不存在');'只是爲了檢查錯誤信息是否會顯示在開發環境。忘了刪除它,但一旦我做了頁面正常工作 – utkarsh2k2

+0

如何,永遠www.blore.eduflats.com仍然顯示500服務器錯誤 – utkarsh2k2