0

I use annotations to define routes in my project. I have a controller method that has such a route:

/**
* @Route("/{slug}", name="showcompany")
*/
public function show(Company $company): Response
{
...
}

This is done to catch requests like website.com/company1, website.com/company2, etc...

I get this error:

"App\Entity\Company object not found by the @ParamConverter annotation."

Since obviously all other routes such as website.com/signup are considered as slugs of the Company entity.

The question is how to avoid this behavior without moving all routes to routes.yaml and ordering them manually? I want all routes to be prioritized over this /{slug} route.

Dhia Djobbi
  • 1,176
  • 2
  • 15
  • 35
  • 2
    Starting in 5.1 you can add a [route priority](https://symfony.com/doc/current/routing.html#priority-parameter). For older versions of Symfony, you can still use a yaml file to create this particular route and then ensure it gets loaded last. There are actually a number of almost identical question out there. Search first and avoid the lectures and down votes. – Cerad Aug 17 '21 at 18:42
  • 1
    @Cerad thank you! This actually solves my question, could you please post it as an answer? – John Wick Aug 17 '21 at 18:46

0 Answers0