Article.php 1.3 KB

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