简体   繁体   English

处理方法不允许在 slim 3 中

[英]Handle Method not allowed in slim 3

Need you help to figure this out.需要你帮忙解决这个问题。 i developed my website in Slim 3 framework.我在 Slim 3 框架中开发了我的网站。 I wanted to handle " Method not allowed. Must be one of: POST " message which i get when i am using browser back and forward buttons.我想处理“不允许的方法。必须是:POST ”消息之一,这是我在使用浏览器后退和前进按钮时收到的。

I want to redirect to a different page when if the route is post and when user clicks on browser back or forward page.

When the post route is called is there a way where i can detect the that it is post method call and redirect him to a different get route.当 post 路由被调用时,有没有一种方法可以让我检测到它是 post 方法调用并将他重定向到不同的 get 路由。

You can add your own handler for specific errors: 您可以为特定的错误添加自己的处理程序:

$container['notAllowedHandler'] = function (ServerRequestInterface $request, ResponseInterface $response, array $methods) {
    // you can return a redirect response
};

see more here 在这里看到更多

Another syntax solution另一种语法解决方案

$notAllowedHandler = function ($c) {
    return function ($request, $response) use ($c) {
        return $response
            ->withJson(
                [
                    "status" => false,
                    "message" => "Your custom message",
                    "data" => [],
                ]
            )
            ->withStatus(400);
    };
};

$app = new App(
    [
        'notAllowedHandler' => $notAllowedHandler,
    ]
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 方法不允许。 必须是 POST slim 3 之一 - Method not allowed. Must be one of the POST slim 3 Slim Framework:方法不允许方法不允许。 必须是以下之一:POST - Slim Framework: Method not allowed Method not allowed. Must be one of: POST 苗条框架方法不允许使用中间件进行异常处理 - slim framework method not allowed exception handling with middleware 苗条的骨架框架Post Method给出“不允许的方法” - slim skeleton framework Post Method gives “Method not allowed” 未捕获的 Slim\\Exception\\HttpMethodNotAllowedException:方法不允许。 必须是以下之一:GET - Uncaught Slim\Exception\HttpMethodNotAllowedException: Method not allowed. Must be one of: GET 不允许使用Slim Framework方法。 必须是以下之一:POST(405) - Slim Framework Method not allowed. Must be one of: POST (405) 方法不允许。 必须是以下之一:POST - Slim Framework - Method not allowed. Must be one of: POST - Slim Framework 不允许使用方法(405)必须为以下之一:GET-Slim3 + Apache + AWS - Method not allowed (405) Must be one of: GET - Slim3 + Apache + AWS 处理 Slim PHP 中的条纹错误 - Handle Stripe errors in Slim PHP 如何使用SLIM处理多租户? - How to handle multi tenancy with SLIM?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM