当前位置: 首页 > news >正文

fastadmin多个表crud连表操作步骤

1、crud命令

php think crud -t xq_user_credential  -u  1 -c credential  -i voucher_type,nickname,user_id,voucher_url,status,time  --force=true

在这里插入图片描述
2、修改控制器controller文件

<?phpnamespace app\admin\controller;use app\common\controller\Backend;/*** 凭证信息** @icon fa fa-circle-o*/
class Credential extends Backend
{/*** Credential模型对象* @var \app\admin\model\Credential*/protected $model = null;public function _initialize(){parent::_initialize();$this->model = new \app\admin\model\Credential;}/*** 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改*//*** 查看*/public function index(){//当前是否为关联查询$this->relationSearch = false;//设置过滤方法$this->request->filter(['strip_tags', 'trim']);if ($this->request->isAjax()) {//如果发送的来源是Selectpage,则转发到Selectpageif ($this->request->request('keyField')) {return $this->selectpage();}list($where, $sort, $order, $offset, $limit) = $this->buildparams();$where =  'a.voucher_url  IS NOT NULL'. ' AND a.voucher_url <> ""'.' AND b.nickname <> ""'.' AND b.nickname IS NOT NULL';$list = $this->model->alias('a')  // 给主表设置别名->join('xq_user_info b', 'a.user_id = b.user_id', 'left')  // 内连接->where($where)  // 添加查询条件// ->order($sort, $order)  // 排序->paginate($limit);  // 分页       foreach ($list as $row) {$row->visible(['id','voucher_type','nickname','user_id','voucher_url','status','time']);}// 获取 voucher_type 的值并显示异常或正常foreach ($list->items() as $item) {if ($item->voucher_type == 1) {$item->voucher_type="工作认证";} elseif ($item->voucher_type == 2) {$item->voucher_type="房产认证";}elseif ($item->voucher_type == 3) {$item->voucher_type="车辆信息";}elseif ($item->voucher_type == 4) {$item->voucher_type="单身承诺书";}elseif ($item->voucher_type == 5) {$item->voucher_type="诚信承诺书";}elseif ($item->voucher_type == 6) {$item->voucher_type="友好承诺书";}elseif ($item->voucher_type == 7) {$item->voucher_type="信息保密协议";}elseif ($item->voucher_type == 8) {$item->voucher_type="学历认证";}elseif ($item->voucher_type == 9) {$item->voucher_type="体检认证";}elseif ($item->voucher_type == 10) {$item->voucher_type="实名认证";}else {$item->voucher_type="其他类型";}if ($item->status == 1) {$item->status="已认证";}if ($item->status == 0) {$item->status="未认证";}}$result = array("total" => $list->total(), "rows" => $list->items());return json($result);}return $this->view->fetch();}}

其中where条件的写法

            $where =  'a.voucher_url  IS NOT NULL'. ' AND a.voucher_url <> ""'.' AND b.nickname <> ""'.' AND b.nickname IS NOT NULL';

表连接的写法

            $list = $this->model->alias('a')  // 给主表设置别名->join('xq_user_info b', 'a.user_id = b.user_id', 'left')  // 内连接->where($where)  // 添加查询条件// ->order($sort, $order)  // 排序->paginate($limit);  // 分页   

特定字段做显示处理写法

// 获取 voucher_type 的值并显示异常或正常foreach ($list->items() as $item) {if ($item->voucher_type == 1) {$item->voucher_type="工作认证";} elseif ($item->voucher_type == 2) {$item->voucher_type="房产认证";}elseif ($item->voucher_type == 3) {$item->voucher_type="车辆信息";}elseif ($item->voucher_type == 4) {$item->voucher_type="单身承诺书";}elseif ($item->voucher_type == 5) {$item->voucher_type="诚信承诺书";}elseif ($item->voucher_type == 6) {$item->voucher_type="友好承诺书";}elseif ($item->voucher_type == 7) {$item->voucher_type="信息保密协议";}elseif ($item->voucher_type == 8) {$item->voucher_type="学历认证";}elseif ($item->voucher_type == 9) {$item->voucher_type="体检认证";}elseif ($item->voucher_type == 10) {$item->voucher_type="实名认证";}else {$item->voucher_type="其他类型";}if ($item->status == 1) {$item->status="已认证";}if ($item->status == 0) {$item->status="未认证";}}

页面显示js路径
在这里插入图片描述页面中修改的地方
在这里插入图片描述

define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {var Controller = {index: function () {// 初始化表格参数配置Table.api.init({extend: {index_url: 'credential/index' + location.search,add_url: 'credential/add',edit_url: 'credential/edit',del_url: 'credential/del',multi_url: 'credential/multi',import_url: 'credential/import',table: 'user_credential',}});var table = $("#table");// 初始化表格table.bootstrapTable({url: $.fn.bootstrapTable.defaults.extend.index_url,pk: 'id',sortName: 'id',columns: [[{checkbox: true},{field: 'voucher_type', title: __('Voucher_type'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},{field: 'nickname', title: __('Nickname'),operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},{field: 'user_id', title: __('User_id'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},{field: 'voucher_url', title: __('Voucher_url'), operate: 'LIKE', formatter: Table.api.formatter.url},{field: 'status', title: __('Status')},{field: 'time', title: __('Time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}]]});// 为表格绑定事件Table.api.bindevent(table);},add: function () {Controller.api.bindevent();},edit: function () {Controller.api.bindevent();},api: {bindevent: function () {Form.api.bindevent($("form[role=form]"));}}};return Controller;
});

其中

 {field: 'nickname', title: __('Nickname'),operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},

是新加的列

http://www.lryc.cn/news/485910.html

相关文章:

  • 山西省网络建设与运维第十八届职业院校技能大赛(样题)
  • 服务端高并发分布式结构进阶之路
  • 分布式微服务项目,同一个controller不同方法间的转发导致cookie丢失,报错null pointer异常
  • STM32 ADC --- 任意单通道采样
  • vscode中执行git合并操作需要输入合并commit信息,打开的nano小型文本编辑器说明-
  • 蓝桥杯每日真题 - 第7天
  • 【Git】Git Clone 指定自定义文件夹名称:详尽指南
  • 终端快捷键学习笔记
  • Go语言24小时极速学习教程(四)MySQL数据库的增删改查
  • 04 - Clickhouse-21.7.3.14-2单机版安装
  • 多项式回归
  • vscode报错:Connecting with SSH time-out.
  • python可视化将多张图整合到一起(画布)
  • C函数如何返回参数lua使用
  • pytest在conftest.py中实现用例执行失败进行截图并附到allure测试报告
  • 编程之路,从0开始:数据在内存中的存储
  • 二叉树+树的OJ题讲解
  • 信捷PLC转以太网连接电脑方法
  • 释放 PWA 的力量:2024 年的现代Web应用|React + TypeScript 示例
  • CVSS4与CVSS3的不同之二
  • 【Pip】如何清理 `pip` 包管理器 —— 完整指南
  • 操作数据库
  • lua-lru缓存算法解析
  • Python - 初识Python;Python解释器下载安装;Python IDE(一)
  • 鸿蒙学习基本概念
  • 正则表达式(补充)
  • 第23课-C++-红黑树的插入与旋转
  • 【C#】C#编程入门指南:构建你的.NET开发基础
  • [系统安全] PE文件知识在免杀中的应用
  • 相机标定原理