我如何在 codeigniter 中生成/解析这个 RESTful url
我是 MVC、RESTful 和 CodeIgniter 的新手。 我试图在业余时间研究它们,所以这很大程度上是一个学术问题。 我正在尝试构建一个 URL,用于显示特定酒店的特定酒店房间的可用性。 我认为执行此操作的 RESTful 方法如下:
http://url/Hotel/2/RoomAvailability/3/
- “Hotel”是控制器
- “2”是酒店 ID
- “RoomAvailability”是方法
- “3”是房间 ID
我如何在 codeigniter 中设置控制器来处理这? 目前我想我可以执行以下任一操作:
- 使用 mod_rewrite 执行某些操作以重定向到 RoomAvailability() 方法
- 使用 index() 方法执行某些操作并重定向到 RoomAvailability() 方法
实际上,这是一个非常普遍的问题,因为我只想能够执行以下操作:
http://url/model/method-argument/method-name/more-method-arguments
老实说,我很难想出搜索术语来找出要使用的内容(除了 RESTful 和 CodeIgniter,它们并没有太大帮助0。
我真的只是在寻找指导;而不是找人为我编写控制器。另外,如果我要使用这个 URL因为这太可怕了,而且一点也不宁静;请随时指出更好的方法。
I'm new to MVC, being RESTful, and CodeIgniter. I'm trying to get into them in my spare time, so this is largely an academic question. I'm trying to build a URL that will display the availability of a particular hotel room, for a particular hotel. I figured the RESTful way to do this would be the following:
http://url/Hotel/2/RoomAvailability/3/
- "Hotel" is the controller
- "2" is the hotel ID
- "RoomAvailability" is the Method
- "3" is the Room ID
How would I set up my controller in codeigniter to handle this? Currently I'm thinking I could do either of the following:
- Do something with mod_rewrite to redirect to the RoomAvailability() method
- Do something with the index() method and redirect to the RoomAvailability() method
Really this is a pretty generic question, as I just want to be able to do the following:
http://url/model/method-argument/method-name/more-method-arguments
I'm honestly having a hard time coming up with search terms to find out what to use (other than RESTful and CodeIgniter, which havent been too helpful0.
I'm really just looking for guidance; not for someone to write my controller for me. Also, if this URL that I'm going for is horrible, and not RESTful at all; please feel free to point out a better way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那么这个 url 设置怎么样:
然后你可以这样做:
What about this url set up:
Then you could do something like this:
查看 CI 用户指南,特别是有关路由的部分。
https://www.codeigniter.com/user_guide/general/routing.html
Checkout the CI User Guide, specifically the part on routing.
https://www.codeigniter.com/user_guide/general/routing.html