SlimJson
, (*1)
This is an extension to the Slim Framework to implement JSON output., (*2)
Install
Via Composer, (*3)
``` bash
$ composer require buagern/slim-json, (*4)
or adding this line to your composer.json file
``` bash
"buagern/slim-json": "0.1.*"
Usage
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), (*5)
``` php
require 'vendor/autoload.php';, (*6)
$app = new \Slim\Slim();, (*7)
$app->view(new \Buagern\SlimJson\View);
$app->add(new \Buagern\SlimJson\Middleware);, (*8)
### Using Routing Middleware method
``` php
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',
]);
});
Security
If you discover any security related issues, please email buagern@buataitom.com instead of using the issue tracker., (*9)
Credits
License
The MIT License (MIT). Please see License File for more information., (*10)