Reputation: 65
I try to make a RESTful api using slim framework. I do not know details about the slim framework, because i'm beginner of this framework. So, I followed all steps of how to get data in slimframework. But i can't get POST data.
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
$app->post('/registration/user', function (Request $request, Response $response) use ($app) {
$data = $request->getParsedBody();
$name = $_POST['name'];
echo '1 : '.$data['name'];
echo '2 : '.$name;
});
what i have to do for get post data?? Do you have any idea?
Upvotes: 2
Views: 3326
Reputation: 1
The following can be used:
$body= file_get_contents("php://input");
// $body = $request->getBody();
$data = json_decode($body, true);
Upvotes: 0
Reputation: 142
I use \Slim\Http\Request $request->getParsedBody()
in my routes. The method contains all the $_POST data.
Example:
$postArr = $request->getParsedBody();
$name = $postArr["name"];
Upvotes: 2