这是 一鱼CRUD后台AphpAdmin 的API首页,可以自由修改,添加接口方法快速调用数据。
文件:app/api/controller/Test.php:
namespace app\api\controller;
class Test extends Base
{
// 默认接口
public function index()
{
$this->_json(200, '', ['name' => 'AphpAdmin_v1']);
}
// 直接获取
public function get1()
{
return db('test')->where('status=1')->cache()->select();
}
// 通用获取
public function get2()
{
$data = db('test')->where('status=1')->cache()->select();
if (empty($data)) {
$this->error('记录不存在');
}
$this->_json(200, '请求成功', $data);
}
}
用AJAX请求:http://crud.aphp.top/api.php/test/get2.html
可在 config/response.php 设置返回字段:
'ret' => 'code', // 状态码字段
'msg' => 'msg', // 返回信息字段
'data' => 'data', // 返回数据字段
'status' => 'status', // 状态字段:1成功(状态码<400),0失败(状态码>=400)
框架官网:aphp.top | CMS官网:aphpcms.com | 技术联系:无念(24203741@qq.com) | Powered by AphpAdmin v1.0