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
  • 相关阅读:
    Python内置函数(22)——list
    Git在不同环境换行符设置
    Spring之AOP
    Spring之IOC
    Spring--框架简介
    git-远程协作
    git-SSH连接配置
    git-本地操作
    git简介
    浅谈Sql各种join的用法
  • 原文地址:https://www.cnblogs.com/roseY/p/9810397.html
Copyright © 2011-2022 走看看