How to detect HTTP method in CodeIgniter

你。 提交于 2019-12-03 18:57:14

问题


How can I detect HTTP method in CodeIgniter controller class?

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


回答1:


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



回答2:


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



回答3:


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



来源:https://stackoverflow.com/questions/11189969/how-to-detect-http-method-in-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!