zoukankan      html  css  js  c++  java
  • Fastadmin 后台表单,外键关键,步骤

    1.在 publicassetsjsackend 目录中找到对应的js,修改

    2.对应控制器中加上index()方法;开启关联查询

    重点:

    protected $relationSearch = true; //开启关联查询

    public function index()
    {

    //设置过滤方法
    $this->request->filter(['strip_tags']);
    //当前是否为关联查询
    $this->relationSearch = true; // 解决排序问题
    if ($this->request->isAjax()) {
    //如果发送的来源是Selectpage,则转发到Selectpage
    if ($this->request->request('keyField')) {
    return $this->selectpage();
    }
    list($where, $sort, $order, $offset, $limit) = $this->buildparams();
    $total = $this->model
    ->with(['choice'])
    ->where($where)
    ->order($sort, $order)
    ->count();

    $list = $this->model
    ->with(['choice'])
    ->where($where)
    ->order($sort, $order)
    ->limit($offset, $limit)
    ->select();

    $list = collection($list)->toArray();
    $result = array("total" => $total, "rows" => $list);

    return json($result);
    }
    return $this->view->fetch();
    }

    3.对应模型中model 中加上关联的方法

    public function choice()
    {
    return $this->belongsTo('Choices', 'dw_id', 'id', [], 'LEFT')->setEagerlyType(0);   // Choices ------- 需要关联的模型  ;  dw_id ----- 外键id ; id ------ 关联表的id
    }

    4. 最终效果图

    5.最后还有些小问题,为什么做了以上的步骤之后,只显示字段名,最后一步,同步语言包,把需要用的语言同步即可

    详细文档,可查

    https://doc.fastadmin.net/docs/controller.html#关联查询-5
  • 相关阅读:
    Java高级部分--工具类(1)
    Javascript 与正则表达式
    Java基础部分--面向对象基础(1)
    Java基础部分--面向对象高级特性(2)
    持久层框架--hibernate(4)
    持久层框架--hibernate(3)
    持久层框架--hibernate(2)
    python常见面试题
    单元测试之写用例(全局变量,异常处理,断言)
    jmeter安装踩坑记录
  • 原文地址:https://www.cnblogs.com/roseY/p/9810397.html
Copyright © 2011-2022 走看看