How to handle errors 404, 500, 409 etc.?
In version 3, this happened through containers. How about 3? So in version 3:
$c = new \Slim\Container();
$c['notFoundHandler'] = function ($c) {
return function ($request, $response) use ($c) {
return $response->withStatus(404)
->withHeader('Content-Type', 'text/html')
->write('Page not found');
};
};
$app = new \Slim\App($c);
How about 4?
And does anyone know how to get the name of the router that was executed?
For example: $app->get('/', Home::class . ':get')->setName('home');
I want to use RouteContex :: fromRequest () in the middleware, but the error is:
Fatal error: Uncaught RuntimeException: Cannot create RouteContext before routing has been completed in G:\Program\OSPanel\domains\Slim4\vendor\slim\slim\Slim\Routing\RouteContext.php on line *30*
RuntimeException: Cannot create RouteContext before routing has been completed in G:\Program\OSPanel\domains\Slim4\vendor\slim\slim\Slim\Routing\RouteContext.php on line *30*