如何进行MVC表单url格式化? [英] How to do MVC form url formatting?

查看:27
本文介绍了如何进行MVC表单url格式化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PHP.我想从头开始创建 MVC 设置,以了解有关 MVC 工作原理的更多信息.我想使用带有斜杠的干净 url 作为参数的分隔符.当涉及到 GET 方法表单时,人们如何做到这一点?还是人们一起避免使用 GET 方法形式?

I am using PHP. I want to create an MVC setup from scratch to learn more about how MVC works. I want to use clean urls with slashes as delimiters for the arguments. How do people do this when it comes to GET method forms? Or do people avoid GET method forms all together?

目前我能想到的方法是:

As of right now the ways I can imagine are:

  1. 不要使用 GET 方法表单(尽管在某些情况下这会使用户难以添加书签/链接).
  2. 使用 AJAX 而不是表单提交(尽管您对 SEO 和 JS 禁用者做了什么?).
  3. 使用 post 方法将页面提交给自身,然后将 post vars 重新转换为 url,然后使用标题重新路由到该 url(似乎是浪费资源).

欢迎提出任何建议或建议阅读.

Any suggestions or suggested reading welcome.

推荐答案

获取变量和干净的 URL 并不矛盾.你总是可以有像

Get variables and clean URLs don't contradict each other. You can always have URLs like

http://example.com/controller/action?value1=foo&value2=bar

另一种 URL 样式也可能看起来像

An alternative URL style could also look like

http://example.com/controller/action/value1/foo/值2/条或者http://example.com/controller/action/foo/bar

在这两种情况下,如果您想通过表单 GET 提交创建这些 URL,则必须使用 JavaScript 来组合正确的 URL,因此第一个解决方案可能更容易实现.

In these 2 cases if you want to create these URLs via a form GET submit you will have to use JavaScript to assemble the correct URL therefore the very first solution might be easier to implement.

另一个问题是 POST 和 GET 表单提交之间的决定.POST 更安全,但正如您所说,用户无法为其添加书签.

Another question is the decision between POST and GET form submission. POST is more secure but as you said, users can't bookmark it.

这篇关于如何进行MVC表单url格式化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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