symfony - 无法覆盖 symfony 5 异常模板
问题描述
我按照 Symfony 当前文档覆盖异常模板: 如何自定义错误页面
在我的 AccesDeniedListener.php 类中,我放了:
public function onKernelException(ExceptionEvent $event, string $eventName = null): void
{
$exception = $event->getThrowable();
if (!$exception instanceof AccessDeniedException) {
return;
}
// ... perform some action (e.g. logging)
// optionally set the custom response
$event->setResponse(new Response(null, 403));
// or stop propagation (prevents the next exception listeners from being called)
//$event->stopPropagation();
}
我已经安装了 symfony/twig-pack
在我的模板文件夹中,我添加了 Execption twigs :
最后我的新树枝没有被应用
解决方案
如果您的应用程序环境设置为 prod,您应该获得自定义错误页面。如果您的应用程序环境设置为 dev,那么您仍然会收到开发错误消息。要在 dev 中测试您的自定义页面,您可以按照您遵循的指南中的说明添加特殊路线。
# config/routes/dev/framework.yaml
_errors:
resource: '@FrameworkBundle/Resources/config/routing/errors.xml'
prefix: /_error
使用 dev 中的配置,您应该能够访问http://example.com/_error/403。
推荐阅读
- apache-spark - GraphFrames 和标签传播
- c# - UWP 中 XAML 行为(托管)导致的不可预测的样式更改
- python - 基于子串匹配和字符串索引从字符串中获取子串
- python - Python:处理巨大的向量
- kendo-ui - Kendo DropDownList 未在 KendoTreeView 中打开
- websocket - redux-saga、websockets 和动作队列
- c# - 努力连接sql server数据库
- dart - How to generate 6 digit random number
- vue.js - VueJS 2:子级不会在父级更改时更新(道具)
- javascript - Angular - 如何设置
价值与操作?