Closed burzum closed 4 years ago
I'd need a little more context for what you're trying to achieve.
@philipobenito frameworks like Cake allow you to do reverse routing like
$this->Html->link('Foo Index', ['controller' => 'Foo', 'action' => 'index');
// /foo
$this->Html->link('View of a Record', ['controller' => 'Foo', 'action' => 'view', 'slug' => $slug);
// /foo/view/my-slug-var
to generate the route for it. Reversing the concept of routing a request, but resolving the URL by it's route params.
Some other routers allow you to build a route by using named routes like this one https://github.com/crysalead/router See https://github.com/crysalead/router#named-routes-and-reverse-routing
It's not really built in the same way as those routers, there is a way to set/get named routes and then you can infer a link from that, however, that will slow down the resolution of the route as it is then handled separately from un-named routes, which are just passed off to FastRoute.
$router->get('/example')->setName('example');
/** @var \League\Route\Route $exampleRoute */
$exampleRoute = $router->getNamedRoute('example');
To implement something fully to replicate the example above would slow down resolution of routes significantly at the moment so it's not something I'd consider adding right now.
There is no support for reverse routing?