![]() |
Checking if a request is POST? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Checking if a request is POST? (/showthread.php?tid=27787) |
Checking if a request is POST? - El Forum - 02-20-2010 [eluser]Unknown[/eluser] How can I check if a request was submitted with the POST method (does CI offer a shorter way than "if($_SERVER['REQUEST_METHOD'] === 'POST')")? Checking if a request is POST? - El Forum - 02-20-2010 [eluser]sqwk[/eluser] Code: $something = $this->input->post('something'); http://ellislab.com/codeigniter/user-guide/libraries/input.html Checking if a request is POST? - El Forum - 02-20-2010 [eluser]skunkbad[/eluser] [quote author="squawk" date="1266706903"] Code: $something = $this->input->post('something'); http://ellislab.com/codeigniter/user-guide/libraries/input.html[/quote] That only checks for the existence of $_POST['something'], so it won't work. Checking if a request is POST? - El Forum - 02-20-2010 [eluser]heavenquake[/eluser] I don't believe there is, but you could write a quick helper function that did it for you. Personally I extend input->post() to, if no argument is given, return TRUE if anything has been posted at all. You might want to do something similar. Checking if a request is POST? - El Forum - 02-20-2010 [eluser]Unknown[/eluser] How do you override controller methods, preserving the old one? Like in Ruby I'd do Code: class Controller Sorry for the example in another lang, my PHP is rusty. Checking if a request is POST? - El Forum - 02-20-2010 [eluser]heavenquake[/eluser] input->post is not a controller method, but a method of the input library ( http://ellislab.com/codeigniter/user-guide/libraries/input.html ). In CodeIgniter you extend core libraries (such as input) by placing a file called MY_Input.php in your libraries folder, with the following prototype: Code: class MY_Input extends CI_Input { in your case it would be something alá: Code: class MY_Input extends CI_Input { Checking if a request is POST? - El Forum - 02-21-2010 [eluser]hugle[/eluser] [quote author="heavenquake" date="1266739418"]input->post is not a controller method, but a method of the input library ( http://ellislab.com/codeigniter/user-guide/libraries/input.html ). In CodeIgniter you extend core libraries (such as input) by placing a file called MY_Input.php in your libraries folder, with the following prototype: Code: class MY_Input extends CI_Input { in your case it would be something alá: Code: class MY_Input extends CI_Input { thank you very much for this extension,it's more like CI style. ![]() I used to use this: Code: if($_POST) |