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 hexo+github部署博客
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?