I have a controller which implements all routes/URL(s). I had the idea to offer a generic index over all help-pages.
Is there a way to get all routes defined by a controller (from within a controller) in Symfony2
?
I have a controller which implements all routes/URL(s). I had the idea to offer a generic index over all help-pages.
Is there a way to get all routes defined by a controller (from within a controller) in Symfony2
?
If anyone is stumbling on this issue, this is how I exported the routes in the global twig scope (symfony 4).
src/Helper/Route.php
src/config/packages/twig.yaml
Then in your twig file to populate a javascript variable to use in your scripts
What you can do is use the cmd with (up to SF2.6)
With SF 2.7 the command is
With SF 3.0 the command is
which shows you all routes.
If you define a prefix per controller (which I recommend) you could for example use
to display all matching routes
To display get all your routes in the controller, with basically the same output I'd use the following within a controller (it is the same approach used in the router:debug command in the symfony component)
routes.html.twig
Output will be:
/_wdt/{token} ANY web_profiler.controller.profiler:toolbarAction
etc.I was looking to do just that and after searching the code, I came up with this solution which works for a single controller (or any ressource actually). Works on Symfony 2.4 (I did not test with previous versions) :
In Symfony 4 i wanted to get all the routes including controller and actions in one list. In rails you can get this by default.
In Symfony you need to add the parameter
show-controllers
to thedebug:router
command.If somebody looking for the same feature it can be get with:
this will produce a list like the following
You could get all of the routes, then create an array from that and then pass the routes for that controller to your twig.
It's not a pretty way but it works.. for 2.1 anyways..