junker/silex-jsend

Silex JSend 组件

0.2.0 2016-06-05 08:13 UTC

This package is auto-updated.

Last update: 2024-09-10 22:06:22 UTC


README

Silex 的 JSend 组件

需求

silex 1.x, 2.x

##安装 安装 SilexJsend 的最佳方式是使用 Composer

php composer.phar require junker/silex-jsend

示例

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);
});

##文档 http://silex.sensiolabs.org/doc/master/usage.html#traits