I have added route to update emails in a database which uses PUT method
$app->put('/notifications/{email}', 'add_email_address');
and function for it looks like:
function add_email_address($request, $response, $args) {
$email = $args['email'];
$addon_email = $request->getParam('addon_email', null);
echo "ADD/UPDATE $email with $addon_email";
}
UPDATE somehow on testing PUT method with a form input post addon_email = test@null.com
retrieved value for $addon_email
is empty;
Any tips what I'm doing wrong?
I have got it to work by changing
$addon_email = $app->request->getParam('addon_email', null);
to
$allPostPutVars = $request->getParsedBody();
$addon_email = $allPostPutVars['addon_email'];
It looks like getParam
works only for GET method. Also content-type must be set as x-www-form-urlencoded