Search code examples
phpannotationssymfony4symfony-routing

Symfony Routing or Symfony Annotations?


I am starting a new symfony web app and i want this project to be as clean as possible. I can't make the decision between routing annotations or base symfony routing in my routes.yml file. Is there any pros and cons to either?


Solution

  • In production, they are both exactly the same - the annotations and/or routing configuration files (be they yaml, xml or php sourced) are all compiled into an optimised regex that is matched from the URL path, to the controller action.

    I tend towards mostly annotations on controllers actions (keeping the config close to the actions, as phpdoc annotations), and yaml routing files for the more general other routes, such as redirections.

    It is entirely your choice as to where they are put.