【问题标题】:In Symfony is it possible to if a route matched, forward to other route在 Symfony 中,如果路由匹配,是否可以转发到其他路由
【发布时间】:2018-08-05 21:56:16
【问题描述】:

我在两个单独的包中有两条路由:bundleA_route、bundleB_route。在我的 /app/config/routing.yml 中,我将它们作为资源加载,例如:

bundle_a_routing:
    resource: "@SomeABundle/Resources/config/routing.yml"
    prefix:   /

bundle_b_routing:
    resource: "@SomeBBundle/Resources/config/routing.yml"
    prefix:   /

在大多数情况下,此序列是必需的,首先尝试匹配bundle_a_routing 中的路由,然后然后尝试匹配bundle_b_routing 中的路由,但只有一种情况我想要做一个例外,我希望在bundle_b_routing 中定义的单个路由在bundle_a_routing 中定义的更“让步”路由之前匹配:

route_in_bundle_a:
    path: /admin/{path}
    defaults: { _controller: SomeABundle:SomeCtrl:someAction }
    methods: [GET]
    requirements:
        path: ^(.*)$

route_in_bundle_b:
    path: /admin/download/{formId}/{fileName}
    defaults: { _controller: SomeBBundle:SomeOtherCtrl:someOtherAction }
    methods: [GET]
    requirements:
        formId: \d+
        fileName: ^([a-fA-F0-9]{32}(?:\.[a-zA-Z0-9]{1,222})?)$

现在请求 URI "http://servername/web/app_dev.php/admin/download/12/23d2fff7f606e93acac9ede5b4e2b394.png" 匹配第一个,但我想匹配第二个......这种情况下的官方场景是什么?

【问题讨论】:

  • 您确定您的route_in_bundle_b 随时都会被调用吗?在我看来,route_in_bundle_a 以任何方式取代了它。您能否提供一个 URL,请求将通过route_in_bundle_a 并到达route_in_bundle_b

标签: symfony


【解决方案1】:

你应该改变你导入路由的顺序,这样路由http://servername/web/app_dev.php/admin/download/12/23d2fff7f606e93acac9ede5b4e2b394.png会先触发route_in_bundle_b,没有下载段的路由不会触发,会触发route_in_bundle_a规则。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-12
    • 2013-11-11
    • 2013-09-24
    • 2019-02-22
    • 2021-02-26
    • 2020-04-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多