how to use slim redirect
Slim allows you to name routes, and then redirect back to them based upon this name, using urlFor()
. In your example, change your route to:
$app->get('/', function() use ($app) { ... })->name("root");
and then your redirection becomes:
$app->response->redirect($app->urlFor('root'), 303);
See Route Helpers in the Slim documentation for more information.
From Slim3 docshttp://www.slimframework.com/docs/start/upgrade.html
$app->get('/', function ($req, $res, $args) { return $res->withStatus(302)->withHeader('Location', 'your-new-uri');});
Slim 3
$app->get('/', function ($req, $res, $args) { $url = 'https://example.org'; return $res->withRedirect($url);});
Reference: https://www.slimframework.com/docs/v3/objects/response.html#returning-a-redirect