显示缺少控制器的默认浏览器403 HTTP代码页。 Cakephp 4.3

发布于 2025-01-26 08:01:26 字数 188 浏览 2 评论 0原文

我发现的所有答案都不涵盖最新的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

装迷糊 2025-02-02 08:01:26

我认为您可以通过添加一个新的中间件来做到这一点,该中间件捕获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 throws Cake\Http\Exception\ForbiddenException.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文