JSON PUT request using Slim framework
I am trying to make a PUT request for Slim using the following code:
<script type = "text/javascript"> function submitform() { var url = '/users/' + $('#user_id').val(); $('#myform').attr('action', url); var data = JSON.stringify({"value": $('#user_data').val()}); $('<input type="hidden" name="json"/>').val(data).appendTo('#myform'); $("#myform").submit(); } </script> <form id = "myform" method="post"> id: <input type = "text" id = "user_id"> data: <input type = "text" name = "value" id = "user_data"> <input type="hidden" name="_METHOD" value="PUT"/> <input type = "button" value = "submit" onClick='submitform()'> </form> My index.php file contains:
$app->put('/users/:id', 'update'); function update($id) { $jsonmessage = \Slim\Slim::getInstance()->request(); $message = json_decode($jsonmessage->getBody()); // what do I put here ???? } What should I put in place of ???? to retrieve a parameter value. I see this if I use $ _POST ['json'], but I don't think it is REST compatible. Everything that I tried, for example $ message-> value, does not work (returns nothing).
Thanks.
UPDATE:
Someone from the Slim forum provided the following answer:
$json = $jsonmessage->put('json'); $message = json_decode($json);