我该如何在CodeIgniter控制器类中检测HTTP方法?
编辑:
除了在CodeIgniter中使用$_SERVER ['REQUEST_METHOD']
之外,还有其他方法吗?
我该如何在CodeIgniter控制器类中检测HTTP方法?
编辑:
除了在CodeIgniter中使用$_SERVER ['REQUEST_METHOD']
之外,还有其他方法吗?
感谢Branden,我找到了答案。$this->input->server($index)
与$_SERVER[$index]
是完全相同的。
要获取请求方法,您可以使用:$this->input->server('REQUEST_METHOD')
。
更新:(感谢Ecir Hana)
从CodeIgniter 3开始,也可以使用method来获取请求方法:
echo $this->input->method(TRUE); // Outputs: POST
echo $this->input->method(FALSE); // Outputs: post
echo $this->input->method(); // Outputs: post
在 CodeIgniter 3 中,您可以使用 Input 类的 method 方法。
根据文档:
echo $this->input->method(TRUE); // Outputs: POST
echo $this->input->method(FALSE); // Outputs: post
echo $this->input->method(); // Outputs: post
$this->input->post()
或$this->input->get()
函数。$this->input->post(); // 返回所有未经 XSS 过滤的 POST 项目
,因此这并没有真正回答问题,因为它获取数据而不是检测 HTTP 方法。 - Thomas Welton
$_SERVER
变量是真的吗? - Sgn.