【问题标题】:How can I check if request was a POST or GET request in codeigniter?如何检查请求是 codeigniter 中的 POST 还是 GET 请求?
【发布时间】:2014-10-31 20:29:20
【问题描述】:

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

那么Codeigniter 有这样的东西吗?

$this->container->isGet();

【问题讨论】:

    标签: php codeigniter request http-post http-get


    【解决方案1】:

    我从未使用过codeigniter,但为此我检查了$_SERVER['REQUEST_METHOD']。

    看看the docs 可能是这样的:

    if ($this->input->server('REQUEST_METHOD') === 'GET') {
       //its a get
    } elseif ($this->input->server('REQUEST_METHOD') === 'POST') }
       //its a post
    }
    

    如果您要经常使用它,那么为它滚动您自己的 isGet() 函数很简单。

    【讨论】:

    • 它有效,但它不是为 CI 执行此操作的方法;见 input->method()。
    【解决方案2】:

    对于 CodeIgniter 3 用户:the docs state 输入类具有获取请求方法的功能:

    echo $this->input->method(TRUE); // Outputs: POST
    echo $this->input->method(FALSE); // Outputs: post
    echo $this->input->method(); // Outputs: post
    

    【讨论】:

    【解决方案3】:

    在codeigniter 4中:

    $this->request->getMethod() // Returns get, post, or whatever the method is
    

    【讨论】:

      猜你喜欢
      • 2014-01-30
      • 1970-01-01
      • 2010-11-25
      • 2014-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-31
      • 2017-10-30
      相关资源
      最近更新 更多