首先找到你当前的文章类后台控制器。
一般在application/admin/controller 下面
先添加模型use app\admin\model\Type as TypeModel;
然后覆盖index方法
public function index()
{
//设置过滤方法
$this->request->filter(['strip_tags']);
if ($this->request->isAjax())
{
//如果发送的来源是Selectpage,则转发到Selectpage
if ($this->request->request('keyField'))
{
return $this->selectpage();
}
$typeName = TypeModel::column('id,name');
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$total = $this->model
->where($where)
->order($sort, $order)
->count();
$list = $this->model
->where($where)
->order($sort, $order)
->limit($offset, $limit)
->select();
$list = collection($list)->toArray();
foreach ($list as $k => &$v)
{
$v['type_text'] = isset($typeName[$v['type_id']]) ? $typeName[$v['type_id']] : "";
}
unset($v);
$result = array("total" => $total, "rows" => $list);
return json($result);
}
return $this->view->fetch();
}
修改前台js:后台对应的js 一般在 public/assets/js/backend 目录下跟控制器同名
把:
{field: 'type_text', title: __('type_id'),operate:false,formatter: Table.api.formatter.label},