I searched, but I didn't find an answer. I have a RESTful API to manage a basic CRUD. I'm trying to create an update method using PUT, but I can't retrieve the params values. I'm using Postman to make the requests, my request looks like:
URL
http://localhost/api/update/987654321
Params
id = 987654321
name = John Smith
age = 35
PHP
$app = new Slim();
$app->put('/update/:id', function( $id ) use( $app ){
var_dump([
'id' => $id,
'name' => $app->request->put('name'),
'age' => $app->request->put('age')
]);
});
My var_dump()
result is:
array(3) {
["id"]=>
string(9) "987654321"
["name"]=>
NULL
["age"]=>
NULL
}
What is wrong? Any idea?
parse_str(file_get_contents("php://input"),$post_vars);
– MongoosePOST
to update is a bad pratice? – PardonPOST
data, i copied the code from another site. However the PUT data is set in the body of the request just like with all other types of request apart from GET (although you might be able to attach a body string to a GET request, I've never tried it). You could doparse_str($app->request->getBody(), $vars);
and do a var_dump on that to see your data. – Mongoose