我只想问,octobercms只能设置两种类型的错误吗???
404 [通过创建带有/404 url 的页面]
500 [通过创建带有/error url 的页面]
我们如何设置 400、401、402、403、503、400 等?????
最佳答案
这 2 个是特殊情况,作者已经在 Cms Main Controller
中编写了代码,但对于其他情况,我们需要自己编写代码:)
嗯,所有这些都与 HttpException
有关,所以这是我们实际设置和抛出的代码,
App::abort(403, 'Access is forbidden to the requested page.' /* message */);
现在这些都是HttpException
,我们可以使用App::error
拦截它们。您需要将此代码添加到您的 plugin boot
方法中。
//\App::error(function(\Exception $exception) { // for handling all Exceptions
// for handling http related exceptions
\App::error(function(
\Symfony\Component\HttpKernel\Exception\HttpException $exception) {
dd($exception->getStatusCode()); /* 403 */ // 400, 401, 402, 403, 503, 400 etc
// Handle the exception...
});
您可以在此处查看status-code
并根据需要进行处理。
引用:https://octobercms.com/docs/services/error-log#http-exceptions
关于OctoberCMS 401、402、403、503、400错误代码处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50303801/