問題描述
我正在使用 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/值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模板網!