一、新建數據表
二、後臺命令行生成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";