I have a problem right now with CodeIgniter : I use the REST Controller library (which is really awesome) to create an API but I can not get PUT requests…
This is my code :
function user_put() {
$user_id = $this->get("id");
echo $user_id;
$username = $this->put("username");
echo $username;
}
I use curl to make the request :
curl -i -X PUT -d "username=test" http://[...]/user/id/1
The user_id is full but the username variable is empty. Yet it works with the verbs POST and GET.
Have you any idea please?
Thank you !
According to: http://net.tutsplus.com/tutorials/php/working-with-restful-services-in-codeigniter-2/ we should consult https://github.com/philsturgeon/codeigniter-restserver/blob/master/application/libraries/REST_Controller.php#L544 to see that this method:
looks to see if we’ve defined the HTTP header
HTTP_X_HTTP_METHOD_OVERRIDEand it uses that in favor of the actual verb we’ve implemented on the web. To use this in a request you would specify the headerX-HTTP-Method-Override: method(soX-HTTP-Method-Override: put) to generate a custom method override. Sometimes the framework expectsX-HTTP-Methodinstead ofX-HTTP-Method-Overrideso this varies by framework.If you were doing such a request via jQuery, you would integrate this chunk into your ajax request: