How to detect HTTP method in CodeIgniter

2019-02-02 02:31发布

How can I detect HTTP method in CodeIgniter controller class?

Edited: Is there any other way than using $_SERVER['REQUEST_METHOD'] in CodeIgniter?

3条回答
虎瘦雄心在
2楼-- · 2019-02-02 03:14

You can detect GET and POST by using the Input library.

$this->input->post() or $this->input->get()

More information can be found: http://ellislab.com/codeigniter%20/user-guide/libraries/input.html

查看更多
smile是对你的礼貌
3楼-- · 2019-02-02 03:22

Thanks to Branden, I've found the answer. $this->input->server($index) is identical to $_SERVER[$index].

To get method you can use: $this->input->server('REQUEST_METHOD').

UPDATE: (thanks to Ecir Hana)

As of CodeIgniter 3, using of method is also possible:

echo $this->input->method(TRUE); // Outputs: POST
echo $this->input->method(FALSE); // Outputs: post
echo $this->input->method(); // Outputs: post
查看更多
欢心
4楼-- · 2019-02-02 03:28

In CodeIgniter 3, you can use the method uhm...method of Input Class.

From the docs:

echo $this->input->method(TRUE); // Outputs: POST
echo $this->input->method(FALSE); // Outputs: post
echo $this->input->method(); // Outputs: post
查看更多
登录 后发表回答