123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <?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,
- ]);
- return View::fetch();
- }
- /**
- * 关于&留言
- */
- public function about()
- {
- return View::fetch();
- }
- public function guestBook()
- {
- $data = GuestBook::getGuestBooks();
- View::assign('data', $data);
- return View::fetch();
- }
-
- public function saveGuestBook(Request $request = null)
- {
- $param = $request->param();
- if (empty($param['author']) or empty($param['email'])) {
- View::assign('data', ['msg'=>"请填写必填字段(姓名,电子邮件)", 'code'=>1]);
- return View::fetch('error');
- }
- if (empty($param['comment'])) {
- View::assign('data', ['msg'=>"请留下内容", 'code'=>1]);
- return View::fetch('error');
- }
- array_pop($param);
- try {
- $bgu = new GuestBook();
- $res = $bgu->save([
- 'comment' => $param['comment'],
- 'author' => $param['author'],
- 'email' => $param['email'],
- 'url' => $param['url'],
- 'time' => time(),
- ]);
- } catch (\Exception $e) {
- $msg = $e->getMessage();
- View::assign('data', ['msg'=>$msg, 'code'=>1]);
- return View::fetch('error');
- }
- $this->redirect(url('blog/index/guestbook'), 302);
- }
- }
|