PHP code example of buagern / slim-json

1. Go to this page and download the library: Download buagern/slim-json library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

buagern / slim-json example snippets

 php
pp = new \Slim\Slim();

$app->view(new \Buagern\SlimJson\View);
$app->add(new \Buagern\SlimJson\Middleware);
 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',
    ]);
});