How to get all router as array or sitemap


#1

because i have hundred of router, now i want to create a router sitemap.

but i dont know how to do this?

i have read the slim 3 user guide, but did not find any clue.

thanks


#2

You can use public method getRoutes() which returns the $this->routes[] array of route objects.
From the route object you can get the route pattern using the getPattern() method:

$routes = $app->getContainer()->router->getRoutes();
// And then iterate over $routes

foreach ($routes as $route) {
    echo $route->getPattern(), "<br>";
}