Reputation: 515
Can I user post method both for create and update?
I have tried "PUT" method for updating resources, but I am not getting the parameters on server side.
Upvotes: 0
Views: 788
Reputation: 9547
Yes. Due to lack of consistent client implementations for PUT or DELETE methods, standard practice is to send a POST request and either A) use a query string parameter (i.e. ?_method=PUT
) or B) send an X-METHOD-OVERRIDE
header.
(Quick Google search returned this: http://www.endurasoft.com/Blog/post/X-HTTP-Method-Override.aspx)
You would probably need to extend the CI_Input class to know the difference between a create action and an update.
Upvotes: 0
Reputation: 1747
PUT isn't handled natively through PHP (i.e. $_PUT) nor through CodeIgniter. Two things to do off of the top of my head: 1) Grab the PUT variables youreself or 2) Use Phil Sturgeon's REST library.
//put an associative array into $post_vars variable
parse_str(file_get_contents("php://input"),$post_vars);
Source: http://www.lornajane.net/posts/2008/accessing-incoming-put-data-from-php
However, since you are working with CodeIgniter, you should use Phil Sturgeon's library if you can't find a genuine reason not to. It's tried, true, and tested and handles all of the HTTP verbs.
https://github.com/philsturgeon/codeigniter-restserver
Upvotes: 1