Answer by Sajjad Ashraf for Slim JSON Outputs
This is how I do it in slim version 2$app->response->headers->set("Content-Type", 'application/json');return $app->response->write(json_encode(['status' => true,'message' => 'Your...
View ArticleAnswer by Sumit Shinde for Slim JSON Outputs
header("Content-Type : application/json"); echo json_encode($data);
View ArticleAnswer by Sumit Shinde for Slim JSON Outputs
//JSON output in slim3$app->get('/users', function($request,$response,$args) { require 'db_connect.php'; $stmt = $pdo->query("SELECT * FROM users"); $result=$stmt->fetchAll(PDO::FETCH_ASSOC);...
View ArticleAnswer by Nanhe Kumar for Slim JSON Outputs
You can use in slim3, Slim’s Response object custom method withJson($data, $status, $encodingOptions) $app->get('/hello/{name}', function ($request, $response, $args) { $data['msg']='Hello...
View ArticleAnswer by user3104260 for Slim JSON Outputs
[BEFORE]: Content-Type text/html; charset=UTF-8 Not working with SOAPUI JSON :($this->get('get_all', function ($req, $res, $args) { $um = new UserModel(); return $res ->withHeader('Content-Type',...
View ArticleAnswer by jeff_drumgod for Slim JSON Outputs
Using Slim 3, I'm using this format:<?php$app = new \Slim\App();$app->get('/{id}', function ($request, $response, $args) { $id = $request->getAttribute('id'); return $response->withJSON(...
View ArticleAnswer by emccracken for Slim JSON Outputs
I use https://github.com/entomb/slim-json-api for my API written in Slim 2 to enable JSON-response. Init code looks something like this:function APIRequests () { $app = \Slim\Slim::getInstance();...
View ArticleAnswer by ЮрийШпакович for Slim JSON Outputs
Use Slim JSON API https://coderwall.com/p/otcphg/create-a-json-restfull-api-using-slim-framework. You can handle JSON output with it.
View ArticleAnswer by Andreas Bergström for Slim JSON Outputs
Since everyone has complicated their answers with functions and classes, I'll throw in this simplified answer. The \Slim\Http\Response can do it for you like this:$app = new...
View ArticleAnswer by d3nnis for Slim JSON Outputs
you can extend slim with an output function which output is depending the REST request was called:class mySlim extends Slim\Slim { function outputArray($data) {...
View ArticleAnswer by Kristian for Slim JSON Outputs
I feel your pain. I wanted to make a reusable function, so I made a helpers file, and included this:function toJSON($app, $content) { $response = $app->response; $response['Content-Type'] =...
View ArticleAnswer by pikknz for Slim JSON Outputs
My fix was adding "exit;" at the end of the json print out, my dev server didn't care, but my live server would not trigger the json end event. I did not need to add headers or use json_encode.
View ArticleAnswer by Dharani Dharan A for Slim JSON Outputs
I think Slim also provides a middleware object which does this automatically so users of that framework doesnt have to write json_decode and encode on every request, its called the...
View ArticleAnswer by k33g_org for Slim JSON Outputs
why not $response->write(json_encode($dataAry)); instead of echo json_encode($dataAry); ?
View ArticleAnswer by jmk2142 for Slim JSON Outputs
Why not just use Slim's Response Object? (also... why exit?)$dataAry = // Some data array$response = $app->response();$response['Content-Type'] = 'application/json';$response['X-Powered-By'] =...
View ArticleAnswer by hakre for Slim JSON Outputs
header("Content-Type: application/json");echo json_encode($result);exit;Hint: Using The Slim PHP Framework for Developing REST APIs
View ArticleAnswer by genesis for Slim JSON Outputs
function _die($array){ echo json_encode($array); exit;}$result = mysql_query("SELECT * FROM table");while($row = mysql_fetch_assoc($result)){ $array[] = $row;}_die($array);
View ArticleSlim JSON Outputs
I am using the Slim framework with PHP to create a RESTful API for my app. However, I assumed that the framework would have some way of creating easier JSON outputs rather than just...
View Article
More Pages to Explore .....