使用注释对路由进行排序 [英] Ordering of routes using annotations

查看:19
本文介绍了使用注释对路由进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当你在 symfony 中创建路由并且你想要一个像这样的路由时的常用解决方案

The usual solution when you create routes in symfony and you want to have one route like

/{username}

这样它就不会与/login 或/info 等其他路由发生冲突,只是将该路由作为您的 routing.yml 文件中的最后一条路由.由于所有其他路由优先,因此避免了这种冲突.但是,如果您将路由定义为控制器中的注释,您怎么能做到这一点呢?在这种情况下,有没有办法指定这条路线的顺序?

so that it does not conflict with other routes like /login or /info is just to put that route as your last route in your routing.yml file. Since all the other routes take precedence this conflict is avoided. But how can you do this if you define your routes as annotations in your controllers? Is there any way to specify the ordering of this routes in this case?

推荐答案

在控制器的上下文中,动作方法的顺序定义了路由的顺序.在整个应用的上下文中,可以显式导入每个控制器来控制顺序,例如:

In the context of a controller, the order of action methods defines the order of routes. In the context of the whole application, you can import each controller explicitly to control the order, for example:

Home:
    resource: "\Vendor\Controller\HomeController"
    type: annotation

Security:
    resource: "\Vendor\Controller\SecurityController"
    type: annotation

security.log_out:
    pattern: "/logout"

User:
    resource: "\Vendor\Controller\UserController"
    type: annotation

这篇关于使用注释对路由进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆