简体   繁体   中英

Routing in Symfony

I have two links:

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

and:

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

I would like makes links for this

http://www.mypage.com/linksone

and

http://www.mypage.com/linkstwo

Is it possible to do that with Symfony routing system?

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

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

Where I can add ID?

I believe this should do it:

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

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

If you want to do this in Symfony 2+ you need to do the following routing, hopefully someone will find this useful. This is just an example and not using your names/routes.

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+

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM