PHP code example of junker / silex-jsend

1. Go to this page and download the library: Download junker/silex-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/ */

    

junker / silex-jsend example snippets



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