junker/silex-jsend

Silex JSend Component

0.2.0 2016-06-05 08:13 UTC

This package is auto-updated.

Last update: 2024-11-10 22:30:24 UTC


README

JSend Component for Silex

Requirements

silex 1.x, 2.x

##Installation The best way to install SilexJsend is to use a Composer:

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