|
@@ -0,0 +1,90 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+declare(strict_types=1);
|
|
|
+/**
|
|
|
+ * +----------------------------------------------------------------------
|
|
|
+ * 文章控制制器
|
|
|
+ * @author huwhis@163.com
|
|
|
+ * @version 0.0.6
|
|
|
+ * +----------------------------------------------------------------------
|
|
|
+ */
|
|
|
+namespace app\controller;
|
|
|
+
|
|
|
+// 引入框架内置类
|
|
|
+use think\facade\View;
|
|
|
+use think\exception\HttpException;
|
|
|
+use think\App;
|
|
|
+
|
|
|
+use app\model\Novel as NovelModel;
|
|
|
+use app\model\NovelData;
|
|
|
+use app\utils\ParsedownUtils;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 文章
|
|
|
+ */
|
|
|
+class Novel extends Base
|
|
|
+{
|
|
|
+ public function __construct(App $app)
|
|
|
+ {
|
|
|
+ parent::__construct($app);
|
|
|
+
|
|
|
+ $eng = View::engine();
|
|
|
+
|
|
|
+ $eng->layout('novellayout');
|
|
|
+ }
|
|
|
+
|
|
|
+ public function index()
|
|
|
+ {
|
|
|
+ $params = $this->app->request->param();
|
|
|
+
|
|
|
+ $list = NovelModel::queryPage($params);
|
|
|
+
|
|
|
+ View::assign('list', $list);
|
|
|
+
|
|
|
+ return View::fetch();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function nlist($id = 0)
|
|
|
+ {
|
|
|
+ $novel = NovelModel::find($id);
|
|
|
+
|
|
|
+ if (!$novel) {
|
|
|
+ throw new HttpException(404, '页面不存在');
|
|
|
+ }
|
|
|
+
|
|
|
+ // $params = $this->app->request->param();
|
|
|
+
|
|
|
+ $list = NovelData::where('n_id', $id)->field('id,n_id,title')->paginate(20);
|
|
|
+
|
|
|
+ View::assign('list', $list);
|
|
|
+
|
|
|
+ View::assign(['id'=>$id,'name'=>$novel->name]);
|
|
|
+
|
|
|
+ return View::fetch();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 阅读文章
|
|
|
+ */
|
|
|
+ public function read($nid = null,$id = null)
|
|
|
+ {
|
|
|
+ $data = NovelData::find($id);
|
|
|
+
|
|
|
+ if (!$data) {
|
|
|
+ throw new HttpException(404, '页面不存在');
|
|
|
+ }
|
|
|
+
|
|
|
+ $prev_next = NovelData::getNextPrev($id, $data->n_id);
|
|
|
+
|
|
|
+ View::assign('nid', $nid);
|
|
|
+ View::assign('data', $data);
|
|
|
+ View::assign('prev_next', $prev_next);
|
|
|
+
|
|
|
+ $this->seo['title'] = $data->title;
|
|
|
+ $this->seo['key'] = "ceshi";
|
|
|
+ $this->seo['des'] = "ceshi";
|
|
|
+ View::assign('seo', $this->seo);
|
|
|
+
|
|
|
+ return View::fetch();
|
|
|
+ }
|
|
|
+}
|