I'm using AltoRouter PHP routes. Everything works fine so far.
But I noticed my index file is getting bigger and kind of hard to maintain because of the growth of the urls I have defined.
I'd like to know if it's possible to use external files to define and group routes and then use it inside the index file, instead of defining everything on index.php.
What I have now is a file like this:
$router = new AltoRouter();
# Posts
$router->map('GET', '/posts', 'PostsController@function');
$router->map('GET', '/posts/[i:id]', 'PostsController@function');
$router->map('POST', '/posts', 'PostsController@function');
$router->map('PUT', '/posts/[i:id]', 'PostsController@function');
# Users
# More routes...
# Services
# More routes...
This way it doesn't seems to be very organized.
I'd like to know if it's possible to put, for example, all the posts routes in a file called posts.routes.php and then link it to the index.php file and use it.
The PHP require()
function may be exactly what you need.