PHP code example of junker / symfony-jsend-response

1. Go to this page and download the library: Download junker/symfony-jsend-response 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 / symfony-jsend-response example snippets


use Junker\JsendResponse\JSendResponse;
use Junker\JsendResponse\JSendSuccessResponse;
use Junker\JsendResponse\JSendFailResponse;
use Junker\JsendResponse\JSendErrorResponse;


class AppController
{
	...

	$data = ['id' => 50, 'name' => 'Waldemar'];
	$message = 'Error, total error!';
	$code = 5;

	return new JsendResponse(JSendResponse::STATUS_SUCCESS, $data);
	#or
	return new JsendResponse(JSendResponse::STATUS_FAIL, $data);
	#or 
	return new JsendResponse(JSendResponse::STATUS_ERROR, NULL, $message);
	#or
	return new JsendResponse(JSendResponse::STATUS_ERROR, $data, $message, $code);
	#or
	return new JsendSuccessResponse($data);
	#or
	return new JsendFailResponse($data);
	#or
	return new JsendErrorResponse($message);
	#or
	return new JsendErrorResponse($message, $code, $data);

}