一、控制器部分

<?php

namespace app\user\controller;

use app\user\model\HelpCenterManual as HelpCenterManualModel;
use org\Response;
use app\index\logic\Upload;
use think\Controller;
use think\Request;
use org\Ucenter;
use think\Db; /**
* 帮助中心使用手册控制器
* Class Manual
* @package app\user\controller
* @author fgf <2018-05-11>
*/
class Manual extends Controller
{
/**
* 列表数据
* @return array
*/
public function index(Request $request)
{
$page = $request->get('page', 1);//页数
$row = $request->get('row', 2);//每页数据
$source = $request->get('source', '');//版本 0-用户端 1-企业端
//查询模型取数据
$manual = new HelpCenterManualModel();
$manual->getList($page, $row, $source);
//提取模型查询的数据
$total = $manual->total;
$pages = $manual->pages;
$list = $manual->list;
$data = [
'total' => $total,//总的数据量
'page' => $page,//当前页
'pages' => $pages,//总页数
'trainlist' => $list,//每条数据详情
];
return Response::response(0, $data);
} public function create()
{
//
} public function save(Request $request)
{
//
} /**
* 详情页数据
* @param $id
* @table qj_help_center_manual 使用手册表
* @return array
*/
public function read($id)
{
$info = Db::table('qj_help_center_manual')->where('id',$id)->find();
if (empty($info)) return Response::response(1,[],'数据为空');
//图片路径转oss路径
if (!empty($info['img'])) {
$info['oss_img'] = get_image_url($info['img']);
}else{
$info['oss_img'] = '';
} return Response::response(0,$info);
} public function edit($id)
{ } public function update($id)
{
//
} public function delete($id)
{
//
}
}

二、模型代码

<?php

namespace app\user\model;

use think\Model;
use think\Request;
use think\Db; /**
* 帮助中心常见问题模型
* Class HelpCenterManual
* @package app\user\model
* @author fgf <2018-05-11>
*/
class HelpCenterManual extends Model
{
/**
* @param $page 页数
* @param $row 每页数据
* @param $source 版本 0-用户端 1-企业端
*/
public function getList($page, $row, $source)
{
$offset = ($page - 1) * $row;
$where = [];
//0用户端,1企业端
$where['source'] = $source?$source:0;
//统计总数
$total = Db::table('qj_help_center_manual')->where($where)->count();
//查询列表信息
$list = Db::table('qj_help_center_manual')->where($where)->order('id asc')->limit($offset, $row)->select();
//处理状态和图片路径处理
foreach ($list as $key => &$val) {
//图片path路径转oss路径
if ($val['img'] !='') {
$list[$key]['img']=get_image_url($val['img']);
}
}
$this->pages = ceil($total / $row);
$this->list = $list;
$this->total = $total;
}
}

三、路由定义-此处定义的是资源路由(根据实际情况自己定义)

return [
'__pattern__' => [
'name' => '\w+',
],
'/error' => 'index/error/index',//错误页面
'__rest__' => [ 'user/manual'=>'user/manual',//帮助中心-使用手册
]
];

四、请求数据参考如下

{
"code": 0,
"message": "success",
-"data": {
"total": 2,
"page": "1",
"pages": 2,
-"trainlist": [
-{
"id": 4,
"title": "React的平凡之路",
"guide_read": "React的平凡之路,或许我们才刚刚上路",
"content": "<h1 style=\"font-size: 2.5rem;margin: 0.67em 0px;line-height: 1.5;color: rgb(51, 51, 51);font-family: -apple-system, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Helvetica Neue', Arial, sans-serif;white-space: normal;background-color: rgb(255, 255, 255)\">React的平凡之路,或许我们才刚刚上路</h1><h2 style=\"line-height: 1.5;margin-top: 35px;margin-bottom: 10px;padding-bottom: 12px;font-size: 24px;border-bottom: 1px solid rgb(236, 236, 236)\">大家一起来</h2><p style=\"line-height: inherit;margin-top: 22px;margin-bottom: 22px\">React是一个用于构建用户界面的JS库,核心专注于视图,目的实现组件化开发</p><p style=\"line-height: inherit;margin-top: 22px;margin-bottom: 22px\">所谓组件化开发,其实就像堆积木一样,每个组件都包含了自己的逻辑和样式,然后再组合到一起完成一个复杂的页面</p><p style=\"line-height: inherit;margin-top: 22px;margin-bottom: 22px\">组件化的主要特点就是:<span style=\"font-weight: 700\">可组合、可复用、可维护</span></p><p style=\"line-height: inherit;margin-top: 22px;margin-bottom: 22px\">那么废话不多说,让我们直接进入今天的主题,运用官方推荐的脚手架来搭建一个react项目开始学习吧</p><h2 style=\"line-height: 1.5;margin-top: 35px;margin-bottom: 10px;padding-bottom: 12px;font-size: 24px;border-bottom: 1px solid rgb(236, 236, 236)\">create-react-app启动react项目</h2><p style=\"line-height: inherit;margin-top: 22px;margin-bottom: 22px\">第一步:<span style=\"font-weight: 700\">全局安装create-react-app</span>脚手架</p><pre style=\"font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 1em;line-height: 1.75;overflow: auto;position: relative\">npm&nbsp;i&nbsp;create-react-app&nbsp;-g</pre><p style=\"line-height: inherit;margin-top: 22px;margin-bottom: 22px\">第二步:创建react项目</p><pre style=\"font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 1em;line-height: 1.75;overflow: auto;position: relative\">create-react-app&nbsp;项目名&nbsp;&nbsp;&nbsp;//&nbsp;如:create-react-app&nbsp;react123</pre><p style=\"line-height: inherit;margin-top: 22px;margin-bottom: 22px\"><br/></p><p><img class=\"lazyload inited loaded\" src=\"https://user-gold-cdn.xitu.io/2018/5/9/163407dd81313cce?imageView2/0/w/1280/h/960/format/webp/ignore-error/1\"/>通过以上操作就会自动创建一个名为react123的react项目了,在创建的过程中,脚手架会自动为你安好react的核心包,<span style=\"font-weight: 700\">react和react-dom</span>,在此过程完成后即可进入第三步了</p><p style=\"line-height: inherit;margin-top: 22px;margin-bottom: 22px\"><br/></p><p style=\"line-height: inherit;margin-top: 22px;margin-bottom: 22px\">第三步:进入项目并启动服务</p><pre style=\"font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 1em;line-height: 1.75;overflow: auto;position: relative\">cd&nbsp;react123&nbsp;&amp;&amp;&nbsp;npm&nbsp;start</pre><p style=\"line-height: inherit;margin-top: 22px;margin-bottom: 22px\"><br/></p><p><img class=\"lazyload inited loaded\" src=\"https://user-gold-cdn.xitu.io/2018/5/9/16340810d2abf3e1?imageView2/0/w/1280/h/960/format/webp/ignore-error/1\"/>通过上面的三步曲,就会自动弹出浏览器访问一个<span style=\"font-weight: 700\">localhost:3000</span>(默认为3000端口)的react页面了</p><p style=\"line-height: inherit;margin-top: 22px;margin-bottom: 22px\"><br/></p><p style=\"line-height: inherit;margin-top: 22px;margin-bottom: 22px\">现在,让我们通过进入创建好的react项目中,先去看一下搭建好的结构是什么样的?</p><p style=\"line-height: inherit;margin-top: 22px;margin-bottom: 22px\">下面就为大家展示一番:</p><p><img class=\"lazyload inited loaded\" src=\"https://user-gold-cdn.xitu.io/2018/5/9/163408396ca911f1?imageView2/0/w/1280/h/960/format/webp/ignore-error/1\"/>根据上图画圈所示,public目录下的index.html表示的是项目的主静态文件(包含依赖的节点),打开后发现一大堆内容,其实都可以删掉,只需要留一个root即可</p><p style=\"line-height: inherit;margin-top: 22px;margin-bottom: 22px\"><br/></p><pre style=\"font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 1em;line-height: 1.75;overflow: auto;position: relative\">&lt;!DOCTYPE&nbsp;html&gt;&nbsp;&lt;html&nbsp;lang=&quot;en&quot;&gt;&nbsp;&nbsp;&nbsp;&lt;head&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;meta&nbsp;charset=&quot;utf-8&quot;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;meta&nbsp;name=&quot;viewport&quot;&nbsp;content=&quot;width=device-width,&nbsp;initial-scale=1,&nbsp;shrink-to-fit=no&quot;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;meta&nbsp;name=&quot;theme-color&quot;&nbsp;content=&quot;#000000&quot;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;link&nbsp;rel=&quot;manifest&quot;&nbsp;href=&quot;%PUBLIC_URL%/manifest.json&quot;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;link&nbsp;rel=&quot;shortcut&nbsp;icon&quot;&nbsp;href=&quot;%PUBLIC_URL%/favicon.ico&quot;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;title&gt;React&nbsp;App&lt;/title&gt;&nbsp;&nbsp;&nbsp;&lt;/head&gt;&nbsp;&nbsp;&nbsp;&lt;body&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div&nbsp;id=&quot;root&quot;&gt;&lt;/div&gt;&nbsp;&nbsp;&nbsp;&lt;/body&gt;&nbsp;&lt;/html&gt;</pre><p style=\"line-height: inherit;margin-top: 22px;margin-bottom: 22px\">说完public后,再说一下src目录,这里面的文件也都可以删掉(除了<span style=\"font-weight: 700\">index.js</span>主入口文件),这里就和webpack4里默认的入口文件比较类似了</p><p><br/></p>",
"img": null,
"addtime": "2018-05-14 17:57:12",
"user_id": null,
"username": "admin",
"source": 1
}
]
}
}

thinkphp5 列表页数据分页查询-带搜索条件的更多相关文章

  1. thinkphp5 列表页数据分页查询3-带搜索条件

    先加载模板然后在前端HTML页面请求数据 /** * 加载列表页模板 * @author 冯广福 */ public function index() { LogWriteService::write ...

  2. thinkphp5 列表页数据分页查询2-带搜索条件

    一.控制器部分 <?php namespace app\user\controller; use app\index\controller\Common; use app\user\model\ ...

  3. python实现列表页数据的批量抓取练手练手的

    python实现列表页数据的批量抓取,练手的,下回带分页的 #!/usr/bin/env python # coding=utf-8 import requests from bs4 import B ...

  4. Oracle、MySql、SQLServer 数据分页查询

    最近简单的对oracle,mysql,sqlserver2005的数据分页查询作了研究,把各自的查询的语句贴出来供大家学习..... (一). mysql的分页查询 mysql的分页查询是最简单的,借 ...

  5. 织梦仿站列表页pagelist分页显示竖排,如何修改成横排?

    织梦仿站列表页pagelist分页显示竖排,如何修改成横排? 织梦列表页的分页标签是采用pagelist来进行调用的,但是很多人在调用之后会出现一个列表竖着排列的问题(横排美观度好一些),还是非常不美 ...

  6. 转Oracle、MySql、SQLServer 数据分页查询

    最近简单的对oracle,mysql,sqlserver2005的数据分页查询作了研究,把各自的查询的语句贴出来供大家学习..... (一). mysql的分页查询 mysql的分页查询是最简单的,借 ...

  7. Oracle、MySql、SQLServer数据分页查询

    看过此博文后Oracle.MySql.SQLServer 数据分页查询,在根据公司的RegionRes表格做出了 SQLserver的分页查询语句: 别名.字段 FROM( SELECT row_nu ...

  8. [.NET] SQL数据分页查询

    [.NET] SQL数据分页查询 程序下载 范例下载:点此下载 原始码下载:点此下载 NuGet封装:点此下载 数据查询 开发系统时,使用C#执行SQL查询指令,就可以从SQL数据库里查询所需数据. ...

  9. Django自定义分页并保存搜索条件

    Django自定义分页并保存搜索条件 1.自定义分页组件pagination.py import copy class Pagination: def __init__(self, current_p ...

随机推荐

  1. MySQL:基础知识

    基础知识 一.软件的生命周期 软件定义 软件开发 软件使用与维护 二.数据(Data) 1.定义 描述客观事物特征或性质的某种符号,经过数字化处理存储在计算机 2.数据独立性 物理独立性:指用户的应用 ...

  2. php session (二): 同样的代码 ,不同域名访问 对session存储的影响.

    一:准备工作: 位置: htdocs a目录: sessiona.php b目录 sessionb.php c目录 sessionc.php ------ sessiona.php <?php ...

  3. 惊不惊喜, 用深度学习 把设计图 自动生成HTML代码 !

    如何用前端页面原型生成对应的代码一直是我们关注的问题,本文作者根据 pix2code 等论文构建了一个强大的前端代码生成模型,并详细解释了如何利用 LSTM 与 CNN 将设计原型编写为 HTML 和 ...

  4. python 正则匹配时间格式转换方法

    import re from datetime import datetime a = '2018年8月9日 10:10' s = re.findall('\d+',a) print(s) d = ' ...

  5. ChainingHash

    public class ChainingHash<Key,Value>{ private int N; private int M; private doublylinked<Ke ...

  6. elementUI 日期 周一、周二、周三、周四、周五、周六、周日快捷键

    <el-date-picker v-model="ruleForm.pickDateMeal" type="daterange" align=" ...

  7. Codeforce 9C - Hexadecimal's Numbers

    One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got ...

  8. Spring Boot 揭秘与实战(五) 服务器篇 - Tomcat 启用 HTTPS

    文章目录 1. 生成证书 2. 配置 HTTPS 支持 3. 启动与测试 4. 源代码 Spring Boot 内嵌的 Tomcat 服务器可以启用 HTTPS 支持. 生成证书 使用第三方 CA 证 ...

  9. 清除chrome浏览器HSTS缓存

    如果你的网站启用了HSTS 在chrome中会用缓存效果,即使你的站点取消了HSTS,下次访问时,仍旧会自动给你重定向到HSTS. 那么如何清除 HSTS呢? chrome://net-interna ...

  10. paddle实践

    Docker image阅读:https://github.com/PaddlePaddle/book/blob/develop/README.cn.md docker run -d -p 8888: ...