如何做MVC表单网址格式? [英] How to do MVC form url formatting?
问题描述
我正在使用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:
- 请勿使用GET方法形式(尽管在某些情况下,这会使用户更难添加书签/链接).
- 使用AJAX代替表单提交(尽管您对SEO和JS禁用者做了什么?).
- 让页面使用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/value2/bar 或者 http://example.com/controller/action/foo/bar
http://example.com/controller/action/value1/foo/value2/bar or 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表单网址格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!