dst67283 2009-03-13 21:48
浏览 5
已采纳

你能强迫symfony解决特定路线吗?

Say that I have to following 2 routes in this order:

Zip:
  url: home/:zip
  param: { module: home, action: results }

State:
  url: home/:state
  param: { module: home, action: results }

and I use a route such as:

'@State?state=CA'

Why does it resolve to the Zip route? I thought when you specified the route name explicitly: '@State' that it did not parse the entire routing file and just used the specific route you asked for.

I would like to be able to use the same action to display data based on the variable name (zip or state) I don't want to have to create the same action (results) twice just to pass in a different parameter.

  • 写回答

3条回答 默认 最新

  • duanpacan2583 2009-03-13 22:01
    关注

    You need to add requirements so that it will recognize the different formats

    Zip:
      url: home/:zip
      param: { module: home, action: results }
      requirements: { zip: \d{5} } # assuming only 5 digit zips
    
    State:
      url: home/:state
      param: { module: home, action: results }
      requirements: { state: [a-zA-Z]{2} }
    

    That should fix it, although I agree with you that when you use a route name in a helper it should use the named route.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 openwrt双栈NAT
  • ¥15 部分网页页面无法显示!
  • ¥15 怎样解决power bi 中设置管理聚合,详细信息表和详细信息列显示灰色,而不能选择相应的内容呢?
  • ¥15 QTOF MSE数据分析
  • ¥15 平板录音机录音问题解决
  • ¥15 请问维特智能的安卓APP在手机上存储传感器数据后,如何找到它的存储路径?
  • ¥15 (SQL语句|查询结果翻了4倍)
  • ¥15 Odoo17操作下面代码的模块时出现没有'读取'来访问
  • ¥50 .net core 并发调用接口问题
  • ¥15 网上各种方法试过了,pip还是无法使用