PHP code example of zlink / supports
1. Go to this page and download the library: Download zlink/supports 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/ */
zlink / supports example snippets
use zlink\Supports\Triats\ResponseTriat;
class BaseController extends Controller
{
use ResponseTriat;
public function index()
{
$headers = [
'Cache-Control': 'no-cache',
'Content-Type': 'text/html; charset=utf-8',
];
$message = 'request success';
$data = [];
// 直接返回
return $this->success($message);
// 返回json
return $this->success($data);
// 指定返回的http状态码
return $this->setStatusCode(10000)->success($message);
// 指定返回json结构 和 headers
return $this->setStatusCode(10000)->respond([
'code' => 10000,
'message' => 'success',
'data' => []
], $headers);
return $this->message('message');
return $this->failed("request faild");
return $this->notLogin();
return $this->notFound();
return $this->internalError();
return $this->created();
}
}