buagern / slim-json
JSON middleware for Slim PHP framework
0.1.2
2015-03-22 03:33 UTC
Requires
- php: >=5.4.0
This package is not auto-updated.
Last update: 2024-12-21 17:53:52 UTC
README
This is an extension to the Slim Framework to implement JSON output.
Install
Via Composer
$ composer require buagern/slim-json
or adding this line to your composer.json file
"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)
require 'vendor/autoload.php'; $app = new \Slim\Slim(); $app->view(new \Buagern\SlimJson\View); $app->add(new \Buagern\SlimJson\Middleware);
Using Routing Middleware method
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.
Credits
License
The MIT License (MIT). Please see License File for more information.