OctoberCMS 401,402,403,503,400错误代码处理

Zak*_*ain 3 octobercms octobercms-plugins

我只需要问是octobercms只能设置两种类型的错误???

  1. 404 [通过使用/ 404 url​​创建页面]

  2. 500 [通过/错误网址创建页面]

我们怎样才能设置400,401,402,403,503,400等??????

Har*_*iya 5

这两个是特殊情况,作者已经编写了代码Cms Main Controller但是对于其他人我们需要自己编写代码:)

嗯所有都与之相关,HttpException所以这就是我们实际设置的代码并像这样抛出,

App::abort(403, 'Access is forbidden to the requested page.' /* message */);
Run Code Online (Sandbox Code Playgroud)

现在这些都是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...
});
Run Code Online (Sandbox Code Playgroud)

你可以status-code在这里查看并随意处理它们.参考:https://octobercms.com/docs/services/error-log#http-exceptions