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.

Usage

  1. <?php
  2. use Slim\Factory\AppFactory;
  3. use Slim\Middleware\MethodOverrideMiddleware;
  4. require __DIR__ . '/../vendor/autoload.php';
  5. $app = AppFactory::create();
  6. // Add RoutingMiddleware before we add the MethodOverrideMiddleware so the method is overrode before routing is done
  7. $app->addRoutingMiddleware();
  8. // Add MethodOverride middleware
  9. $methodOverrideMiddleware = new MethodOverrideMiddleware();
  10. $app->add($methodOverrideMiddleware);
  11. // ...
  12. $app->run();