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:
getRouteCollection()
getRouteCollection()
and save the results in the session, cache etc. Thanks for thinking with me.
Kind regards
I am not exactly sure for what use-case you need this routes but another problem will be that there are routes that you probably dont want to have in your routes list because they are for example routes from the profiler or AJAX routes. So a better approach could be to maintain your own list of routes in a database table where the user can make his choice from.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.