I'm trying to return some content using a Response object. These are the interfaces implemented:
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;
Then, in a GET function, i create my own JSON, and trying to reurn it as a response:
$app->get('/getpersons', function(Request $request, Response $response, $args){
$person= new stdClass();
$person->id = 1;
$person->name='Name example';
$person->address = 'Street example';
return $response->getBody()->write(json_encode($person));
});
But I'm getting the next error:
Return value of Slim\Handlers\Strategies\RequestResponse::__invoke() must
implement interface Psr\Http\Message\ResponseInterface
I don't have any idea what is happening. Any help?
Solved! Must be written like this:
$response->getBody()->write(json_encode($person));
return $response;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With