The usual solution when you create routes in symfony and you want to have one route like
/{username}
so that it does not conflict with other routes like /login or /info is just to put that route as your last route in your routing.yml file. Since all the other routes take precedence this conflict is avoided. But how can you do this if you define your routes as annotations in your controllers? Is there any way to specify the ordering of this routes in this case?
In the context of a controller, the order of action methods defines the order of routes. In the context of the whole application, you can import each controller explicitly to control the order, for example:
Home:
resource: "\Vendor\Controller\HomeController"
type: annotation
Security:
resource: "\Vendor\Controller\SecurityController"
type: annotation
security.log_out:
pattern: "/logout"
User:
resource: "\Vendor\Controller\UserController"
type: annotation
I can't comment on the answer, so I will leave how I had to write it in Symfony 2.3 to get it to work:
Home:
resource: "@AcmeBundle/Controller/HomeController.php"
prefix: /home #optional
type: annotation
Notice the change of "\" to "/" and using .php at the end of controller name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With