Now I read the documentation of Slim. I wanted to create the middleware for example in the doc
<?php
$app = new \Slim\App();
$mw = function ($request, $response, $next) {
$response->getBody()->write('BEFORE');
$response = $next($request, $response);
$response->getBody()->write('AFTER');
return $response;
};
$app->get('/', function ($request, $response, $args) {
$response->getBody()->write(' Hello ');
return $response;
})->add($mw);
$app->run();
But when I execute the code I got the error Too few arguments to function Closure::{closure}(), 2 passed in /home/roma/slim/vendor/slim/slim/Slim/MiddlewareDispatcher.php on line 313 and exactly 3 expected in /home/roma/slim/src/public/index.php:121
I don’t understand what is $next ?