fastadmin后台开发步骤

一、新建数据表

二、后台命令行生成CURD

三、需求:文章有归属分类,我们在列出数据时需要同时列表文章分类名称。(以官网的test表为例,需要做以下操作)

控制器类添加

protected $relationSearch = true;

控制器类重写index方法

public function index()
    {
        if ($this->request->isAjax())
        {
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $total = $this->model
                ->with("category")
                ->where($where)
                ->order($sort, $order)
                ->count();
            $list = $this->model
                ->with("category")
                ->where($where)
                ->order($sort, $order)
                ->limit($offset, $limit)
                ->select();
            $result = array("total" => $total, "rows" => $list, "extend" => ['money' => 1024, 'price' => 888]);
            return json($result);
        }
        return $this->view->fetch();
    }

对应的mode添加

public function category()
    {
        return $this->belongsTo('Category', 'category_id')->setEagerlyType(0);
    }

对应JS代码可以获取类别名称

{field: 'category.name', title: __('分类名称'), formatter:Table.api.formatter.search},

四:需求:后台数据列表开启开关功能

控制器类加上

protected $multiFields = "switch";

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章