方法重写中间件让您能够使用 X-Http-Method-Override
请求头部或请求主体参数 _METHOD
来重写传入请求的方法。该中间件应当在已添加路由中间件后放置。
<?php
use Slim\Factory\AppFactory;
use Slim\Middleware\MethodOverrideMiddleware;
require __DIR__ . '/../vendor/autoload.php';
$app = AppFactory::create();
// Add RoutingMiddleware before we add the MethodOverrideMiddleware so the method is overridden before routing is done
$app->addRoutingMiddleware();
// Add MethodOverride middleware
$methodOverrideMiddleware = new MethodOverrideMiddleware();
$app->add($methodOverrideMiddleware);
// ...
$app->run();