我在控制器中有这样的代码:
if(some stuff) {
throw $this->createNotFoundException('message');
}
我在开发环境测试时,会出现Symfony页面上显示“Exception detected”的提示,但我无法在生产环境下进行测试:( 我运行了以下命令:php app/console cache:clear --env=prod --no-debug
,然后只替换URL中的app_dev.php
为app.php
,但是工具栏和Symfony错误页面还在。
我创建了这个文件-app/Resources/TwigBundle/views/Exception/error.html.twig
。所以它会在生产环境中呈现吗?
该文件包含以下内容:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>An Error Occurred: {{ status_text }}</title>
</head>
<body>
<h1>Oops! An Error Occurred</h1>
<h2>The server returned a "{{ status_code }} {{ status_text }}".</h2>
</body>
</html>
我应该在哪里提供status_code
和status_text
的值?或者它们是从异常中获取的吗?
总的来说,我想做的是当控制器操作中的条件为真时,在生产环境中显示我的自定义错误页面。我已经完成了吗?如果没有,如何实现以及如何在生产环境中查看结果?
index.php
中强制设置$useDebugging = false;
。之后您需要清除缓存。 - gArn