php 如何在 CodeIgniter 中检测 HTTP 方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11189969/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to detect HTTP method in CodeIgniter
提问by Sgn.
How can I detect HTTP method in CodeIgniter controller class?
如何在 CodeIgniter 控制器类中检测 HTTP 方法?
Edited:Is there any other way than using $_SERVER['REQUEST_METHOD']in CodeIgniter?
编辑:除了$_SERVER['REQUEST_METHOD']在 CodeIgniter 中使用还有其他方法吗?
回答by Sgn.
Thanks to Branden, I've found the answer.
$this->input->server($index)is identical to $_SERVER[$index].
感谢布兰登,我找到了答案。
$this->input->server($index)与 相同$_SERVER[$index]。
To get method you can use: $this->input->server('REQUEST_METHOD').
要获取方法,您可以使用:$this->input->server('REQUEST_METHOD')。
UPDATE:(thanks to Ecir Hana)
更新:(感谢Ecir Hana)
As of CodeIgniter 3, using of methodis also possible:
从 CodeIgniter 3 开始,也可以使用 of方法:
echo $this->input->method(TRUE); // Outputs: POST
echo $this->input->method(FALSE); // Outputs: post
echo $this->input->method(); // Outputs: post
回答by Ecir Hana
回答by Branden Martin
You can detect GET and POST by using the Input library.
您可以使用输入库检测 GET 和 POST。
$this->input->post()or $this->input->get()
$this->input->post()或者 $this->input->get()
More information can be found: http://ellislab.com/codeigniter%20/user-guide/libraries/input.html
可以找到更多信息:http: //ellislab.com/codeigniter%20/user-guide/libraries/input.html

