2016-06-10 103 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