0

In a Symfony 6.1 project, I have created a TopicController with

#[Route('/{topic}', name: 'topic.index', methods: ['GET'])]

and then I created PhotographerController with

#[Route('/', name: 'photographer.index', methods: ['GET'], priority: 10)]

Problem:

Now if I try /anytopic , this goes to the TopicController, and /photographers also goes to the TopicController.

Question:

How can I force /photographers controller to go to PhotographerController?

I tried to add priority: 10 to PhotographerController like bellow, but it is not working.

#[Route('/', name: 'photographer.index', methods: ['GET'], priority: 10)]

routes.yaml file

controllers:
    resource: ../src/Controller/
    type: attribute
Ariful Haque
  • 3,662
  • 5
  • 37
  • 59
  • Just to be sure, the route you posted with the priority is the index route, not the photographer one. Is that a typo? – Chris Haas Jul 24 '22 at 12:52
  • And maybe you need a clearing of the cache? I just tried on a fresh project and it all seems to work as advertised. I assume you don't have any routes.yaml files sneaking around. A bit off-topic but if I really needed something like /{topic} which would match lots of stuff then I would make a route file just for it and adjust the Kernel so it was always loaded last and not worry about messing with a bunch of other route priorities. – Cerad Jul 24 '22 at 13:08
  • @ChrisHaas I've updated the question. The route with priority is the photographer.index route. – Ariful Haque Jul 24 '22 at 13:33
  • It Worked! I made a simple mistake. I had another method in Photographer controller and I didn't change the name. So, there were two methods with photographer.index name. After I fixed it, it worked. – Ariful Haque Jul 24 '22 at 13:39
  • @ArifulHaque, I’ve done that a dozen times, too! – Chris Haas Jul 24 '22 at 13:45
  • 1
    @ArifulHaque Glad you got it working. You might consider setting the topic.index priority to -1. That way, all the other routes will match first and saves you from having to set priority on a bunch of other routes. – Cerad Jul 24 '22 at 14:22

0 Answers0