papasmurf/laravel-4-jsend 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

papasmurf/laravel-4-jsend

Composer 安装命令:

composer require papasmurf/laravel-4-jsend

包简介

Laravel 4 standard JSON response format

README 文档

README

According to OmniTI Labs @ http://labs.omniti.com/jsend:

JSend is a specification that lays down some rules for how JSON responses from web servers should be formatted. JSend focuses on application-level (as opposed to protocol- or transport-level) messaging which makes it ideal for use in REST-style applications and APIs.

Laravel (4.2)

Installation

Install this package through Composer by editing your composer.json file to require papasmurf/laravel-4-jsend.

"papasmurf/laravel-4-jsend": "dev-master"

Update Composer from the Terminal / Command-line:

composer update

Once done add the service provider to app/config/app.php

'Papasmurf\JSend\JSendServiceProvider',

After that you are free to add the facade to your list of aliases in app/config/app.php

'JSend' => 'Papasmurf\JSend\Facades\JSend',

All set and done! You can now respond with consistent JSON messages without having to think of the ideal JSON format..ever!

Usage

function doStuff()
{
	return JSend::success([
		'redirect' => URL::action('UsersController@index')
	]);
}

function validateStuff()
{
	return JSend::fail([
		'failed' => $validation->failedFields(),
		'message' => $message
	]);
}

function tryStuff()
{
	try {
		stuff();
	} catch (Exception $e) {
		return JSend::error('whoops!');
	}

	return JSend::success();
}

Standalone

Standalone usage is possible as well and requires a Response object with a json method:

require __DIR__ . '/src/JSend.php';

class Response
{
	public function json($data)
	{
		return json_encode($data);
	}
}

$responder = new Response;
$JSend = new Papasmurf\JSend\JSend($responder);

echo $JSend->success([
    'redirect' => 'mydomain.com/something'
]);

统计信息

  • 总下载量: 34
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-01-22