PHP code example of mix / api-skeleton
1. Go to this page and download the library: Download mix/api-skeleton 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/ */
mix / api-skeleton example snippets
$vega->handle('/users/{id}', [new Users(), 'index'])->methods('GET');
namespace App\Controller;
use App\Container\DB;
use Mix\Vega\Context;
class Users
{
/**
* @param Context $ctx
* @throws \Exception
*/
public function index(Context $ctx)
{
$row = DB::instance()->table('users')->where('id = ?', $ctx->param('id'))->first();
if (!$row) {
throw new \Exception('User not found');
}
$ctx->JSON(200, [
'code' => 0,
'message' => 'ok',
'data' => $row
]);
}
}
json
"scripts": {
"cliserver:start": "php -S localhost:8000 public/index.php",
"swoole:start": "php bin/swoole.php",
"swooleco:start": "php bin/swooleco.php",
"swow:start": "php bin/swow.php",
"workerman:start": "php bin/workerman.php start",
"cli:clearcache": "php bin/cli.php clearcache"
}
php bin/swoole.php start
server {
server_name www.domain.com;
listen 80;
root /data/project/public;
index index.html index.php;
location / {
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
}
}
location ~ ^(.+\.php)(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;