request->param('parent_id', 0, 'intval'); $page = $this->request->param('page', 1, 'intval'); $pageSize = $this->request->param('page_size', 10, 'intval'); $list = Category::getCategoryList($parentId, $page, $pageSize); // 处理图像的 $list->each(function ($item) { $item['image'] = $item['image'] ? cdnurl($item['image']) : ''; }); $this->success('', $list); } /** * 文章列表 */ public function getArticleList() { $categoryId = $this->request->param('category_id', 0, 'intval'); $page = $this->request->param('page', 1, 'intval'); $pageSize = $this->request->param('page_size', 10, 'intval'); $list = ArticleModel::getArticleList($categoryId, $page, $pageSize); $list->each(function ($item) { // 处理图像的 $item['image'] = $item['image'] ? cdnurl($item['image']) : ''; }); $this->success('获取成功', $list); } //文章详情 public function getArticleInfo() { $id = $this->request->param('id', 0, 'intval'); // 验证id是否为空 if (empty($id)) { $this->error('id不能为空'); } $info = ArticleModel::getArticleInfo($id); //判断是否为空 if (!empty($info)) { $info['image'] = $info['image'] ? cdnurl($info['image']) : ''; } $this->success('获取成功', $info); } }