简体   繁体   English

Symfony 路由还是 Symfony 注释?

[英]Symfony Routing or Symfony Annotations?

I am starting a new symfony web app and i want this project to be as clean as possible.我正在启动一个新的 symfony 网络应用程序,我希望这个项目尽可能干净。 I can't make the decision between routing annotations or base symfony routing in my routes.yml file.我无法在 routes.yml 文件中的路由注释或基本 symfony 路由之间做出决定。 Is there any pros and cons to either?两者有什么优缺点吗?

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.在生产中,它们完全相同——注释和/或路由配置文件(无论是 yaml、xml 还是 php 来源)都被编译成一个优化的正则表达式,从 URL 路径匹配到控制器操作。

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.我倾向于主要针对控制器操作进行注释(保持配置靠近操作,如 phpdoc 注释),以及用于更一般的其他路由(例如重定向)的 yaml 路由文件。

It is entirely your choice as to where they are put.将它们放在哪里完全是您的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM