PHP code example of miwebb / jsend

1. Go to this page and download the library: Download miwebb/jsend library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

miwebb / jsend example snippets




use miWebb/JSend/JSend;

$jsend = new JSend('success', $data);
$jsend = new JSend(JSend::SUCCESS, $data);
$jsend = JSend::success($data);

$jsend = new JSend('fail', $data);
$jsend = new JSend(JSend::FAIL, $data);
$jsend = JSend::fail($data);

$jsend = new JSend('error', $data, $message, $code);
$jsend = new JSend(JSend::ERROR, $data, $message, $code);
$jsend = JSend::error($message, $code, $data);

try {
	$jsend = JSend::decode($json);
} catch(UnexpectedValueException $e) {
	// Error message
}

$json = $jsend->decode();
$json = (string) $jsend;

$jsend->send();

$jsend = new JSend(JSend::SUCCESS, $data);
$jsend->__toString();
$jsend->toArray();
$jsend->encode();
$jsend->isSuccess();
$jsend->isFail();
$jsend->isError();
$jsend->getStatus();
$jsend->setStatus($status);
$jsend->getData();
$jsend->setData($data = null);
$jsend->getMessage();
$jsend->setMessage($message = null);
$jsend->getCode();
$jsend->setCode($code = null);
$jsend->send();

JSend::success($data = null);
JSend::fail($data);
JSend::error($message, $code = null, $data = null);
JSend::decode($input);