【问题标题】:Routing in SymfonySymfony 中的路由
【发布时间】:2011-09-26 11:17:43
【问题描述】:

我有两个链接:

http://www.mypage.com/phone/show/id/1

和:

http://www.mypage.com/phone/show/id/2

我想为此建立链接

http://www.mypage.com/linksone

http://www.mypage.com/linkstwo

Symfony 路由系统可以做到这一点吗?

linksone:
  url: /linksone
  param: { module: phone, action: show}

linkstwo:
  url: /linkstwo
  param: { module: phone, action: show}

我可以在哪里添加 ID?

【问题讨论】:

    标签: php symfony1 url-routing


    【解决方案1】:

    我认为应该这样做:

    linksone:
      url: /linksone
      param: { module: phone, action: show, id: 1}
    
    linkstwo:
      url: /linkstwo
      param: { module: phone, action: show, id: 2}
    

    【讨论】:

      【解决方案2】:

      如果您想在 Symfony 2+ 中执行此操作,您需要执行以下路由,希望有人会发现这很有用。这只是一个示例,不使用您的名称/路线。

      home_route:
         path: /home
         defaults: { _controller: DemoCoreBundle:StaticPageController:home }
      
      about_route:
         path: /about
         defaults: { _controller: DemoCoreBundle:StaticPageController:about }
      
      team_route:
         path: /team/{member_id}
         defaults: { _controller: DemoCoreBundle:StaticPageController:team, member_id:null }
         requirements:
             member_id: \d+
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-10-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多