返回了很多无用信息,我们也不需要这样的结构。
{
"current_page": 1,
"data": [
{
"id": 1,
"openid": "abc",
"nickname": "Lucy",
"avatar": "http://avatar.pinxixi.com/0.jpg",
"status": 1,
"last_login_time": 1656553894,
"created": 1656553894,
"updated": 0,
"deleted": 0
}
],
"first_page_url": "/?page=1",
"from": 1,
"last_page": 1,
"last_page_url": "/?page=1",
"links": [
{
"url": null,
"label": "Previous",
"active": false
},
{
"url": "/?page=1",
"label": "1",
"active": true
},
{
"url": null,
"label": "Next",
"active": false
}
],
"next_page_url": null,
"path": "/",
"per_page": 10,
"prev_page_url": null,
"to": 3,
"total": 3
}
我们接口一般这样返回信息:
{
"code": 0,
"msg": "ok",
"data": {
"users": [
{
"id": 1,
"openid": "abc",
"nickname": "Lucy",
"avatar": "http://avatar.pinxixi.com/0.jpg",
"status": 1,
"last_login_time": 1656553894,
"created": 1656553894,
"updated": 0,
"deleted": 0
}
],
"page": {
"limit": 20,
"p": 1,
"total": 2,
"total_page": 1
}
}
}
我们现在用的框架就很简单:
$p = Request::getInt('p', 1);
$page = ['limit' => 20, 'p' => $p];
$users = User::where($where)
->fields('id, nickname, avatar, status, last_login_time, created, updated')
->order('last_login_time DESC')
->page($page)
->select();
return App::result(0, 'ok', [
'users' => $users,
'page' => $page
]);
拿到返回结果可以处理一下再给前端,前端也可以处理的!~
这还用说,只是很麻烦
是的,不过有人需要这些数据的!~
个性化需求请自行扩展,illuminate/pagination是laravel开发组提供的
提供一个 bootstrap 解决,注册到 config/bootstrap.php 中
直接在app/functions.php里面写一个方法就可以了:
怎么使用:
+1