I'm currently stuck with routing in my Symfony4 (4.3) project. My problem is pretty simple, I want to use route annotations in my controllers but I want to defined the order of these one.
For example, if I have two controllers with following routing :
class BarController extends AbstractController{ /** * @Route("/test/{data}", name="app_bar") */ public function index($data) { // ... return $this->render('index.html.twig', ['data' => $data, ]); }}
and
class FooController extends AbstractController{ /** * @Route("/test/my_value", name="app_foo") */ public function index() { // ... return $this->render('index.html.twig', ['data' => 'my_value', ]); }}
In config/routes/annotations.yaml
I define my route like this
app_controllers: resource: ../../src/Controller/ type: annotation
Then if I call /test/my_value
I would like to be redirected to FooController
since his index
action define @Route("/test/my_value", name="app_foo")
but like routes is loaded alphabetically the index
action from BarController
with app_bar
route is called first.
So I have tried to defined following routing :
app_foo_controller: resource: ../../src/Controller/FooController.php type: annotationapp_controllers: resource: ../../src/Controller/ type: annotation
But this didn't work, BarController and his app_bar
route still called before app_foo
route from FooController.
Also, I don't understand the purpose of config/routes/annotations.yaml
vs config/routes.yaml
since both could contains any type of routes... I miss something ?