This is an extension to the Slim Framework to implement JSON output.
Via Composer
$ composer require buagern/slim-json
or adding this line to your composer.json file
"buagern/slim-json": "0.1.*"
To include the middleware and view you just have to load them using the default Slim way. Read more about Slim Here (https://github.com/codeguy/Slim#getting-started)
require 'vendor/autoload.php';
$app = new \Slim\Slim();
$app->view(new \Buagern\SlimJson\View);
$app->add(new \Buagern\SlimJson\Middleware);
function jsonResponse()
{
$app = \Slim\Slim::getInstance();
$app->view(new \Buagern\SlimJson\View);
$app->add(new \Buagern\SlimJson\Middleware);
}
$app->get('/', function () use ($app)
{
// normal view render
return $app->render('view.php');
});
$app->get('/json', 'jsonResponse', function () use ($app)
{
// this request will return json response
return $app->render(200, [
'message' => 'JSON response',
]);
});
If you discover any security related issues, please email buagern@buataitom.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.