1. Go to this page and download the library: Download dconco/phpslides-status 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/ */
dconco / phpslides-status example snippets
namespace PhpSlides\Controller\Api;
use PhpSlides\Controller\Controller;
use PhpSlides\Status;
final class UserController extends Controller
{
public function __invoke() {
$status = new Status();
}
}
use PhpSlides\Http\Response;
Response::JSON;
Response::HTML;
Response::CSV;
Response::XML;
new Status(Response::JSON);
use PhpSlides\Status;
use PhpSlides\Http\Response;
final class UserController extends Controller {
public function __invoke() {
$status = new Status(Response::JSON);
return $status->success();
}
}
return $status->error('User not Found', StatusCode::NOT_FOUND);
namespace PhpSlides\Controller\Api;
use PhpSlides\Controller\Controller;
use PhpSlides\Http\Response;
use PhpSlides\StatusCode;
use PhpSlides\Status;
final class UserController extends Controller
{
public function __invoke(int $user_id) {
$status = new Status();
if ($user_id === 1) {
$user = [
'name': 'John Doe',
'email': '[email protected]',
'user_id': $user_id
];
$response = $status->success($user); // by default the second parameter is `StatusCode::OK`
} else {
// not found message
$response = $status->error("User user_id=$user_id is not found", StatusCode::NOT_FOUND);
}
return $response; // return message as a JSON format `Response::JSON`
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.