如何在codeigniter中检查请求是否是POST或GET请求?

hec*_*aso 12 php codeigniter http-get http-post request

我只是想知道是否有一种非常简单的方法来确定请求是$_POST一个$_GET请求还是一个请求.

这是否Codeigniter有这样的事情?

$this->container->isGet();
Run Code Online (Sandbox Code Playgroud)

cOl*_*le2 34

我从来没有使用过codeigniter但为此我检查了$_SERVER['REQUEST_METHOD'].

查看文档可能是这样的:

if ($this->input->server('REQUEST_METHOD') == 'GET')
   //its a get
else if ($this->input->server('REQUEST_METHOD') == 'POST')
   //its a post
Run Code Online (Sandbox Code Playgroud)

如果您打算使用它,那么简单地isGet()为它推出自己的功能.


Wil*_*jer 6

对于CodeIgniter 3用户:docs声明输入类具有获取请求方法的函数:

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)