我正在使用 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:
欢迎提出任何建议或建议阅读.
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格式化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!