manghe/app/MyController.php
2025-03-22 04:47:34 +00:00

69 lines
1.4 KiB
PHP
Executable File

<?php
declare (strict_types=1);
namespace app;
use think\App;
use think\exception\ValidateException;
use think\Validate;
use think\Request;
/**
* 控制器基础类
*/
abstract class MyController extends BaseController
{
/**
* 返回封装后的 API 数据到客户端
*/
protected function renderJson($status = 1, $msg = '', $data = [])
{
return compact('status', 'msg', 'data');
}
/**
* 返回操作成功json
*/
protected function renderSuccess($msg = 'success', $data = [])
{
return json($this->renderJson(1, $msg, $data));
}
/**
* 返回操作失败json
*/
protected function renderError($msg = 'error', $data = [], $status = 0)
{
return json($this->renderJson($status, $msg, $data));
}
/**
* 返回layui.table格式的数据
*/
protected function renderTable($msg = 'success', $count = 0, $data = [], $code = 0)
{
return json([
'code' => $code,
'msg' => $msg,
'count' => $count,
'data' => $data
]);
}
/**
* 获取post数据 (数组)
*/
protected function postData($key = null)
{
return $this->request->param(is_null($key) ? '' : $key . '/a');
}
/**
* 获取post数据 (数组)
*/
protected function getData($key = null)
{
return $this->request->get(is_null($key) ? '' : $key);
}
}