image.png
image.png
common.php
<?php
// 应用公共文件
function pagination($obj)
{
if (!$obj) {
return '';
}
$params = request()->param();
return '<div class="imooc-app">' . $obj->appends($params)->render() . '</div>';
}
function getCatName($catId)
{
if (!$catId) {
return '';
}
$cats = config('cat.list');
return !empty($cats[$catId]) ? $cats[$catId] : '';
}
function isYesNo($str)
{
return $str ? '<span style="color:red">是</span>' : '<span>否</span>';
}
function status($id, $status)
{
$controller = request()->controller();
$sta = $status == 1 ? 0 : 1;
$url = url($controller . '/status', ['id' => $id, 'status' => $sta]);
if ($status === 1) {
$str = "<a href='javascript:;' title='修改状态' status_url='" . $url . "'
onclick='app_status(this)'><span class='label label-success radius'>正常</span></a>";
} else {
$str = "<a href='javascript:;' title='修改状态' status_url='" . $url . "'
onclick='app_status(this)'><span class='label label-danger radius'>待审</span></a>";
}
return $str;
}
/**
* 通用化API接口数据输出
* @param int $status 业务状态码
* @param string $message 信息提示
* @param [] $data 数据
* @param int $httpcode http状态码
* @return \think\response\Json
*/
function show($status, $message, $data = [], $httpcode = 200)
{
$data = [
'status' => $status,
'message' => $message,
'data' => $data,
];
return json($data, $httpcode);
}
function show($status, $message, $data = [], $httpcode = 200)
{
$data = [
'status' => $status,
'message' => $message,
'data' => $data,
];
return json($data, $httpcode);
}
Test.php
<?php
/**
* Created by PhpStorm.
* User: tong
* Date: 2017/11/15
* Time: 10:23
*/
namespace app\api\controller;
use think\Controller;
class Test extends Controller
{
public function index()
{
return [
'sgsg',
'sgsgs',
];
}
public function update($id = 0)
{
// return $id;//http://singwa.com/test/100
halt(input('put.'));//body提交
}
/**
* post 新增
* @return mixed
*/
public function save()
{
//获取到提交数据 插入库
//给客户端APP =》 接口数据
//201 创建成功
return show(1, 'OK', input('post.'), 201);
}
}
public function save()
{
//获取到提交数据 插入库
//给客户端APP =》 接口数据
//201 创建成功
return show(1, 'OK', input('post.'), 201);
}
image.png
网友评论