Skip to content

alexcane/php-json-response

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tests License

PHPJsonResponse


Personal PHP Class Library for format json response

This is a personal library to standardise my json response on all my projects.

Response structure

  • status : string 'error' or 'success'.
  • error_msg : array of errors message.
  • data : array of data provided.
  • response : mixed value is possible like object, Class or HTML string, etc.

How to use ?

  1. Instance the class
$resp = $new JsonResp(/* array of data */);
  1. Check if your data is valid and add your error message.
if (0 <= $data['number']) $resp->addErrMsg('number must be more than 0');
  1. Before return response you can check if there are errors.
if ($resp->isError()) die $resp->returnResponse(true);
  1. 2 ways to return response : JSON string or Array.
$resp->returnResponse(true); // JSON string
$resp->returnResponse(); // Array

About

Personal PHP Class Library for format json response

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages