Novel.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * +----------------------------------------------------------------------
  5. * 文章控制制器
  6. * @author huwhis@163.com
  7. * @version 0.0.6
  8. * +----------------------------------------------------------------------
  9. */
  10. namespace app\controller;
  11. // 引入框架内置类
  12. use think\facade\View;
  13. use think\exception\HttpException;
  14. use think\App;
  15. use app\model\Novel as NovelModel;
  16. use app\model\NovelData;
  17. use app\utils\ParsedownUtils;
  18. /**
  19. * 文章
  20. */
  21. class Novel extends Base
  22. {
  23. public function __construct(App $app)
  24. {
  25. parent::__construct($app);
  26. $eng = View::engine();
  27. $eng->layout('novellayout');
  28. }
  29. public function index()
  30. {
  31. $params = $this->app->request->param();
  32. $list = NovelModel::queryPage($params);
  33. View::assign('list', $list);
  34. return View::fetch();
  35. }
  36. public function nlist($id = 0)
  37. {
  38. $novel = NovelModel::find($id);
  39. if (!$novel) {
  40. throw new HttpException(404, '页面不存在');
  41. }
  42. // $params = $this->app->request->param();
  43. $list = NovelData::where('n_id', $id)->field('id,n_id,title')->paginate(20);
  44. View::assign('list', $list);
  45. View::assign(['id'=>$id,'name'=>$novel->name]);
  46. return View::fetch();
  47. }
  48. /**
  49. * 阅读文章
  50. */
  51. public function read($nid = null,$id = null)
  52. {
  53. $data = NovelData::find($id);
  54. if (!$data) {
  55. throw new HttpException(404, '页面不存在');
  56. }
  57. $prev_next = NovelData::getNextPrev($id, $data->n_id);
  58. View::assign('nid', $nid);
  59. View::assign('data', $data);
  60. View::assign('prev_next', $prev_next);
  61. $this->seo['title'] = $data->title;
  62. $this->seo['key'] = "ceshi";
  63. $this->seo['des'] = "ceshi";
  64. View::assign('seo', $this->seo);
  65. return View::fetch();
  66. }
  67. }