我只是想知道是否有一种非常简单的方法可以确定请求是$_POST
还是$_GET
请求。
那么Codeigniter
有这样的东西吗?
$this->container->isGet();
我从未使用过codeigniter,但为此我检查了$_SERVER['REQUEST_METHOD']
。
查看文档可能会有以下内容:
if ($this->input->server('REQUEST_METHOD') === 'GET') {
//its a get
} elseif ($this->input->server('REQUEST_METHOD') === 'POST') {
//its a post
}
如果你要经常使用它,那么很容易为它推出自己的isGet()
函数。
对于CodeIgniter 3用户:文档声明输入类具有获取请求方法的函数:
echo $this->input->method(TRUE); // Outputs: POST
echo $this->input->method(FALSE); // Outputs: post
echo $this->input->method(); // Outputs: post
正确答案是:
if ($this->input->post()) {
//have post
}
在代码点火器4:中
$this->request->getMethod() // Returns get, post, or whatever the method is