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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 23:57:09  来源:igfitidea点击:

How to detect HTTP method in CodeIgniter

phpcodeignitercodeigniter-2http-method

提问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

In CodeIgniter 3, you can use the methoduhm...method of Input Class.

在 CodeIgniter 3 中,您可以使用Input Class的方法uhm...method。

From the docs:

从文档:

echo $this->input->method(TRUE); // Outputs: POST
echo $this->input->method(FALSE); // Outputs: post
echo $this->input->method(); // Outputs: post

回答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