12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- declare(strict_types=1);
- /**
- * @file Index.php
- * @date 2019-02-27 14:49:36
- * @author huwhis<huuwhois>
- * @version 0.0.6
- */
- namespace app\index\controller;
- use think\facade\View;
- use think\Request;
- use app\index\controller\Base;
- use app\common\model\Article;
- use app\common\model\GuestBook;
- class Index extends Base
- {
- public function index()
- {
- // PHP $cid = 1;
- $php_data = Article::getListByCid(1, 7);
- // 其他学习笔记 $cid != 1;
- $other_data = Article::getListByCid(-1, 7);
-
- // Top文章
- $top_data = Article::getTop(3);
- // 所有文章
- $all_data = Article::getListByCid(0, 9);
-
- View::assign([
- 'php_data' => $php_data,
- 'other_data' => $other_data,
- 'top_data' => $top_data,
- 'all_data' => $all_data,
- ]);
- $html = View::fetch();
-
- return $html;
- }
- /**
- * 关于&留言
- */
- public function about()
- {
- $html = View::fetch();
- return $html;
- }
- public function guestBook()
- {
- $list = GuestBook::order('id desc')->paginate();
- View::assign('list', $list);
- return View::fetch();
- }
-
- public function saveGuestBook()
- {
- $param = $this->request->param('','',['strip_tags','htmlspecialchars']);
-
- if (empty($param['name']) or empty($param['contact'])) {
- return json(['msg'=>"请填写必填字段(姓名,电子邮件)", 'code'=>1]);
- }
- if (empty($param['content'])) {
- return json(['msg'=>"请留下内容", 'code'=>1]);
- }
- try {
- $bgu = new GuestBook();
- $bgu->save([
- 'content' => $param['content'],
- 'name' => $param['name'],
- 'contact' => $param['contact'],
- 'url' => $param['url'],
- 'time' => time(),
- ]);
- $bgu->datetime = date("Y-m-d", $bgu->time);
- return json(['msg'=>"保存成功", 'code'=>0, 'data'=>$bgu]);
- } catch (\Exception $e) {
- $msg = $e->getMessage();
- return json(['msg'=>$msg, 'code'=>1]);
- }
- }
- }
|