控制层核心:
public function test($GET) {
$page = self::wt(1);
$id = $GET['id'];
$table = $GET['table'];
$data = Permission::getContentById($id, $table);
return [0, '返回成功!', $data, $page[0], $page[1]];
}
public function returnPageTest() {
return [1, 10];
}
public function postTest($POST) {
return [0, '返回成功!', $POST];
}
public static function wt($type,...$data) {
$fn = self::type[$type];
empty($fn) && print_r('wt:方法不存在!') && exit();
return self::$instance->$fn(...$data);
}
public static function get() {
$get = $_GET;
$type = $get['type'];
$fn = self::type[$type];
empty($fn) && print_r('get:方法不存在!') && exit();
unset($get['type']);
return parent::result(...self::$instance->$fn($get));
}
public static function post() {
$post = json_decode(file_get_contents('php://input') , true);
if (array_key_exists('editForm', $post) || array_key_exists('insertForm', $post) || array_key_exists('Form', $post)) {
$type = $post["type"];
$fn = self::type[$type];
empty($fn) && print_r('post:方法不存在!') && exit();
unset($post['type']);
return parent::result(...self::$instance->$fn($post));
} else return parent::result(-1, '提交错误!');
}
接口层:
<?php
namespace app\interfaces;
interface PermissionInterface {
const type = [
0=>'test',//get请求示例demo
1=>'returnPageTest',//function分页示例demo
2=>'postTest',//post请求示例demo
3=>'shareListById',//get通过sid查询单条共享事件
];
/**
* @Copyright: ©XXXXXXXXXXXXXXXX公司
* @description: get请求示例demo
* @param {*} $GET ?type=0&id=1&table=tb_share
* @return JSON
* @author: XXX
* @Date: 2021-04-19 07:52:16
*/
public function test($GET);
/**
* @Copyright:©XXXXXXXXXXXXXXXX公司
* @description: 分页示例demo
* @param {*} self::wt(1)
* @return Array
* @author: XXX
* @Date: 2021-04-19 11:03:05
*/
public function returnPageTest();
/**
* @Copyright: ©XXXXXXXXXXXXXXXX公司
* @description: post请求示例demo
* @param {*} $POST {"editForm": {"aa": 11},"type": 2}
* @return JSON
* @author: XXX
* @Date: 2021-04-19 11:03:09
*/
public function postTest($POST);
}