I'm trying to create a Symfony form with a ChoiceType field that contains all the routes currently available. This form has the purpose of adding these routes to a module in our backend. I've already created a Module and Route entity. These are used to render the correct navigation structure for the users working on a specific module.
I've used Router#getRouteCollection() inside the form controller, using this the routing cache will be rebuild on every request to the page.
I was thinking about a command that uses this method and adds all the routes to the database. However this means that every time a route is added, this command needs to be executed as well. This seems like a step too much for such a simple task.
What would be the best practice to load these routes inside the controller? And would it be possible to do this without:
- Rebuilding the cache every request when using
getRouteCollection() - Executing an extra command every time a route has been added to the Collection
- Creating a controller that uses
getRouteCollection()and save the results in the session, cache etc.
Thanks for thinking with me.
Kind regards