org_heigl/slim-json-helpers

Clone of aporat/slim-json-helpers | Slim3 JSON Request & Response Helpers

1.0.0 2018-06-14 16:11 UTC

This package is auto-updated.

Last update: 2020-07-23 00:37:10 UTC


README

A clone of the removed aporat/slim-json-helpers

Latest Stable Version Composer Downloads Build StatusCode Coverage License

Requirements

  • PHP >= 5.5

Usage

use Slim\Http\Request as Request;
use JsonHelpers\Renderer as JsonRenderer;

$app = new \Slim\App($settings);
$container = $app->getContainer();

// register the json response and error handlers
$jsonHelpers = new JsonHelpers\JsonHelpers($app->getContainer());
$jsonHelpers->registerResponseView();
$jsonHelpers->registerErrorHandlers();


$this->post('/users', function (Request $request, Response $response, $args)
{
  $user_id = $request->getParam('user_id');
  
   $data = [
        'user_id' => $user_id
    ];

    $response = $this->view->render($response, 200, $data);
    return $response;

  });
}