REST 风格的 URLS 和 PHP

2023-10-13php开发问题
6

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

问题描述

我很难理解如何使用 REST 风格的 URL.我能得到一些帮助吗?现在我有一个像这样的查询字符串:

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

我有一个隐藏 .php 扩展名的 mod 重写.我如何

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

  1. 让这个calendar_expanded/date/1270094400成为现实.
  2. $_GET url 之后的值?
  1. Make this calendar_expanded/date/1270094400 happen.
  2. $_GET the values from the url after the fact?

我喜欢它背后的概念,但每天工作 16 小时以满足整个月的最后期限对我的大脑造成了伤害.

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.

感谢您的帮助.

推荐答案

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

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.

这样,每个请求都由框架处理,您可以灵活地设计 URL,但它们应该是什么样子.

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

例如Symfony 支持开箱即用的 RESTful 设计.

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

顺便说一句,RESTful URL 只有在参数以某种方式固定并指定资源(例如博客文章的标题)时才有意义.如果您只想将参数传递给例如控制表的排序(即某物的视图),那么这应该作为普通"GET 参数进入查询字符串.

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.

就您而言,您似乎想控制日历中应显示的日期.我个人只会在这里使用普通的 GET 查询字符串.

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 风格的 URLS 和 PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17