REST风格的URL和PHP [英] REST-style URLS and PHP

查看:135
本文介绍了REST风格的URL和PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我非常难以使用REST风格的URL。我可以得到一些帮助吗?现在我有一个查询字符串,如下所示:



example.com/calendar_expanded?date=1270094400



我有一个mod重写,它隐藏了.php扩展名。我如何


  1. 使此 calendar_expanded / date / 1270094400 发生。
  2. >
  3. $ _ GET 事实之后来自网址的值

我喜欢它背后的概念,但每天工作16小时以满足整个月的截止日期,这对我的大脑产生了负面影响。

感谢帮助。

解决方案

如果您想创建相当多的REST URL,您应该考虑使用PHP框架, 前端控制器设计模式。

这样,每个请求都由框架处理,您可以灵活地设计您的URL,但它们应该看起来像。



例如 Symfony 支持开箱即用的REST风格设计。



BTW RESTful URL只在参数固定并指定资源时才有意义,例如博客文章的标题。如果您只想将参数传递给控制一个表的排序(即某个东西的视图),那么这应该作为一个普通的GET参数进入查询字符串。



在你的情况下,它看起来像你想控制哪一天应该显示在日历中。我个人会在这里使用普通的GET查询字符串。


I'm having a really hard time getting my head around using REST-style URLS. Can I get a little help with this? Right now I have a query string like so:

example.com/calendar_expanded?date=1270094400

I have a mod rewrite that's hiding the .php extension. How do I

  1. Make this calendar_expanded/date/1270094400 happen.
  2. $_GET the values from the url after the fact?

I love the concept behind it but working 16-hour days to meet a deadline for an entire month is taking a toll on my brain.

Thanks for the help.

解决方案

If you want to create quite a lot REST URLs you should consider to use a PHP framework that makes use of the Front Controller design pattern.

This way, every request is processed by the framework and you are flexible to design your URLs however they should look like.

E.g. Symfony supports a RESTful design out of the box.

BTW RESTful URLs only make sense if the parameters are somehow fixed and specify a resource, for example the title of a blog post. If you want to pass a parameter only to e.g. control the sorting of a table (i.e. the view of something) then this should go as a "normal" GET parameter into the query string.

In your case it looks like you want to control what day should be shown in a calendar. I personally would just use the normal GET query string here.

这篇关于REST风格的URL和PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆