ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# Method Overriding Middleware 方法重写的中间件 The Method Overidding Middleware enables you to use the`X-Http-Method-Override`request header or the request body parameter`_METHOD`to override an incoming request’s method. The middleware should be placed after the routing middleware has been added. > 覆盖中间件的方法允许您使用`X-Http-Method-Override`请求头或请求体参数`_METHOD`来覆盖传入请求的方法。 > > 应该在添加路由中间件之后放置中间件。 ## Usage ~~~php <?php use Slim\Factory\AppFactory; use Slim\Middleware\MethodOverrideMiddleware; require __DIR__ . '/../vendor/autoload.php'; $app = AppFactory::create(); //在添加MethodOverrideMiddleware之前添加路由中间件,以便在完成路由之前覆盖该方法 // Add RoutingMiddleware before we add the MethodOverrideMiddleware so the method is overrode before routing is done $app->addRoutingMiddleware(); //添加MethodOverride中间件 // Add MethodOverride middleware $methodOverrideMiddleware = new MethodOverrideMiddleware(); $app->add($methodOverrideMiddleware); // ... $app->run(); ~~~