第一步:
在控制器先复制
/**
* 查看
*/
public function index()
{
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax()) {
//如果发送的来源是Selectpage,则转发到Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$list = $this->model
->with('user')
->where($where)
->order($sort, $order)
->paginate($limit);
$result = array("total" => $list->total(), "rows" => $list->items());
return json($result);
}
return $this->view->fetch();
}
增加关联方法:->with()
第二步,在model里增加
belongsTo()关联
public function user()
{
return $this->belongsTo('app\admin\model\User', 'recommend_user_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
就ok了
还没有人抢沙发呢~