Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
$app->contentType('text/html; charset=utf-8');
header("Content-Type: application/json");
$app->response()->header('Content-Type', 'application/json;charset=utf-8');
I'm stuck... :-/
I've downloaded the
Slim/slim-skeleton
via Composer.
I need to return JSON in my
Route.php
:
$app->get('/getStoresByBounds', function () use ($app, $stores) {
$app->contentType('application/json');
$myStores = $stores->getStores();
$app->response()->write(json_encode($myStores));
$app->stop();
–
–
–
–
$app = new \Slim\App();
$app->get('/getStoresByBounds', function (Request $request, Response $response) {
$myStores = $stores->getStores();
$response->getBody()->write(json_encode($myStores));
$newResponse = $response->withHeader(
'Content-type',
'application/json; charset=utf-8'
return $newResponse;
–
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.