如何在CodeIgniter中检测HTTP方法

Sgn*_*gn. 35 php codeigniter http-method codeigniter-2

如何在CodeIgniter控制器类中检测HTTP方法?

编辑: 除了$_SERVER['REQUEST_METHOD']在CodeIgniter中使用之外还有其他方法吗?

Sgn*_*gn. 59

感谢Branden,我找到了答案. $this->input->server($index)是完全相同的$_SERVER[$index].

要获得方法,您可以使用:$this->input->server('REQUEST_METHOD').

更新:(感谢Ecir Hana)

从CodeIgniter 3开始,也可以使用方法:

echo $this->input->method(TRUE); // Outputs: POST
echo $this->input->method(FALSE); // Outputs: post
echo $this->input->method(); // Outputs: post
Run Code Online (Sandbox Code Playgroud)


Eci*_*ana 17

在CodeIgniter 3中,您可以使用输入类的方法 uhm ...方法.

来自文档:

echo $this->input->method(TRUE); // Outputs: POST
echo $this->input->method(FALSE); // Outputs: post
echo $this->input->method(); // Outputs: post
Run Code Online (Sandbox Code Playgroud)


Bra*_*tin 5

您可以使用输入库检测GET和POST.

$this->input->post() 要么 $this->input->get()

可以找到更多信息:http://ellislab.com/codeigniter%20/user-guide/libraries/input.html

  • 从文档`$ this-> input-> post(); //返回没有XSS过滤器的所有POST项目,所以这并没有真正回答这个问题.因为它获取数据而不是检测HTTP方法. (6认同)
  • 如果(例如发布)请求不包含任何数据,则不起作用. (2认同)