发布于:2023-04-28 15:32:44
https://blog.csdn.net/lihua123456123/article/details/125540304
ThinkPHP关联预载入with
/**
* 获取文章列表
* @param array $where
* @param string $order
*/
public function getPage(array $where = [])
{
$where[] = [ 'site_id', '=', $this->site_id ];
$field = 'id, category_id, site_id, title, intro, summary, image, author, content, visit, visit_virtual, is_show, sort, create_time, update_time';
$order = 'create_time desc';
$search_model = $this->model->where([ [ 'site_id', '=', $this->site_id ] ])->withSearch([ 'title', 'category_id', 'is_show'], $where)->with('articleCategory')->field($field)->order($order);
$list = $this->pageQuery($search_model);
return $list;
}
/**
* 获取文章信息
* @param int $id
*/
public function getInfo(int $id)
{
$field = 'id, category_id, site_id, title, intro, summary, image, author, content, visit, visit_virtual, is_show, sort, create_time, update_time';
$info = $this->model->where([ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ])->with('articleCategory')->field($field)->findOrEmpty()->toArray();
return $info;
}
https://gitee.com/niucloud-team/niucloud-admin/blob/v1.0.0-beta.1/niucloud/app/service/admin/article/ArticleService.php
阅读 551+
10