'How can I check if request was a POST or GET request in codeigniter?

I just wondered if there is a very easy way to determine whether the request is a $_POST or a $_GET request.

So does Codeigniter have something like this?

$this->container->isGet();


Solution 1:[1]

For CodeIgniter 3 users: the docs state the input class has a function to get the request method:

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

Solution 2:[2]

In codeigniter 4:

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 cOle2
Solution 2 Inc33