Article.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace app\api\controller;
  3. use app\api\model\Article as ArticleModel;
  4. use app\api\model\article\Category as CategoryModel;
  5. /**
  6. * 文章控制器
  7. * Class Article
  8. * @package app\api\controller
  9. */
  10. class Article extends Controller
  11. {
  12. /**
  13. * 文章首页
  14. * @return array
  15. */
  16. public function index()
  17. {
  18. // 文章分类列表
  19. $categoryList = CategoryModel::getAll();
  20. return $this->renderSuccess(compact('categoryList'));
  21. }
  22. /**
  23. * 文章列表
  24. * @param int $category_id
  25. * @return array
  26. * @throws \think\exception\DbException
  27. */
  28. public function lists($category_id = 0)
  29. {
  30. $model = new ArticleModel;
  31. $list = $model->getList($category_id);
  32. return $this->renderSuccess(compact('list'));
  33. }
  34. /**
  35. * 文章详情
  36. * @param $article_id
  37. * @return array
  38. * @throws \app\common\exception\BaseException
  39. * @throws \think\Exception
  40. * @throws \think\exception\DbException
  41. */
  42. public function detail($article_id)
  43. {
  44. $detail = ArticleModel::detail($article_id);
  45. return $this->renderSuccess(compact('detail'));
  46. }
  47. }