php 如何在 codeigniter 中检查请求是 POST 还是 GET 请求?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26682920/
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
How can I check if request was a POST or GET request in codeigniter?
提问by hecontreraso
I just wondered if there is a very easy way to determine whether the request is a $_POST
or a $_GET
request.
我只是想知道是否有一种非常简单的方法来确定请求是请求$_POST
还是$_GET
请求。
So does Codeigniter
have something like this?
那么Codeigniter
有这样的东西吗?
$this->container->isGet();
回答by cOle2
I've never used codeigniter but for this I check the $_SERVER['REQUEST_METHOD']
.
我从未使用过 codeigniter,但为此我检查了$_SERVER['REQUEST_METHOD']
.
Looking at the docsmaybe something like:
查看文档可能类似于:
if ($this->input->server('REQUEST_METHOD') == 'GET')
//its a get
else if ($this->input->server('REQUEST_METHOD') == 'POST')
//its a post
If you're going to use it alot then its simple to roll your own isGet()
function for it.
如果您要大量使用它,那么isGet()
为它推出您自己的功能很简单。
回答by Wilco Waaijer
For CodeIgniter 3 users: the docs statethe input class has a function to get the request method:
对于 CodeIgniter 3 用户:文档状态输入类有一个函数来获取请求方法:
echo $this->input->method(TRUE); // Outputs: POST
echo $this->input->method(FALSE); // Outputs: post
echo $this->input->method(); // Outputs: post
回答by Inc33
In codeigniter 4:
在代码点火器 4 中:
$this->request->getMethod() // Returns get, post, or whatever the method is