SilexJsend
JSend Component for Silex, (*1)
Requirements
silex 1.x, 2.x, (*2)
Installation
The best way to install SilexJsend is to use a Composer:, (*3)
php composer.phar require junker/silex-jsend
Examples
class Application extends \Silex\Application
{
use \Junker\Silex\Application\JSendTrait;
}
use \Junker\Symfony\JSendResponse;
$app->get('/', function() use ($app) {
$data = ['id' => 50, 'name' => 'Waldemar'];
$message = 'Error, total error!';
$code = 5;
return $app->jsend(JSendResponse::STATUS_SUCCESS, $data);
#or
return $app->jsend(JSendResponse::STATUS_FAIL, $data);
#or
return $app->jsend(JSendResponse::STATUS_ERROR, NULL, $message);
#or
return $app->jsend(JSendResponse::STATUS_ERROR, $data, $message, $code);
#or
return $app->jsendSuccess($data);
#or
return $app->jsendFail($data);
#or
return $app->jsendError($message);
#or
return $app->jsendError($message, $code, $data);
});
Documentation
http://silex.sensiolabs.org/doc/master/usage.html#traits, (*4)