显示缺少控制器的默认浏览器403 HTTP代码页。 Cakephp 4.3
我发现的所有答案都不涵盖最新的CakePHP版本[4.3.8],只处理如何更改模板。
当缺少控制器时,我想显示HTTP代码403的默认浏览器页面。如何以最简单的方式实现它?没有http 404模板的编辑,只需执行此命令,就是这样:
header("HTTP/1.1 403 Forbidden");
All answers I found do not cover the newest CakePHP version [4.3.8] and only handle how to change the template.
I want to show the default browser page for HTTP code 403 when the controller is missing. How to achieve it in the simplest way? No editing of the HTTP 404 template, just executing this command and that's it:
header("HTTP/1.1 403 Forbidden");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您可以通过添加一个新的中间件来做到这一点,该中间件捕获
cake \ routing \ decret \ sisscontrollerexception
异常,而是抛出cake \ http \ http \ extection \ forbiddenexception
。I think you could do this by adding a new bit of middleware which catches
Cake\Routing\Exception\MissingControllerException
exceptions and instead throwsCake\Http\Exception\ForbiddenException
.