温馨提示:本文共766个字,读完预计2分钟。
thinkphp5 join 使用案例
$join = [
[‘__USER__ u’, ‘f.uid = u.id’]
];
$list = Db::name('feedback')
->field('f.*,u.user_login,u.user_email,u.user_nickname')
->alias('f')->join($join)
->where(function (Query $query) {
$data = $this->request->param();
if (!empty($data[‘uid’])) {
$query->where('u.id', intval($data[‘uid’]));
}
if (!empty($data[‘keyword’])) {
$keyword = $data[‘keyword’];
$query->where('f.content', 'like', "%$keyword%");
}
})
->order("createtime DESC")
->paginate(2);
// 获取分页显示
$page = $list->render();
$this->assign('list', $list);
$this->assign('page', $page);
// 渲染模板输出
return $this->fetch();