Post.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace addons\blog\controller;
  3. use addons\blog\model\Category;
  4. use addons\blog\model\Comment;
  5. use addons\blog\model\Post as PostModel;
  6. /**
  7. * 博客详情
  8. */
  9. class Post extends Base
  10. {
  11. public function index()
  12. {
  13. $diyname = $this->request->param('diyname');
  14. if ($diyname && !is_numeric($diyname)) {
  15. $post = PostModel::getByDiyname($diyname);
  16. } else {
  17. $id = $diyname ? $diyname : $this->request->param('id', '');
  18. $post = PostModel::get($id);
  19. }
  20. if (!$post || $post['status'] != 'normal') {
  21. $this->error("日志未找到");
  22. }
  23. $post->setInc('views');
  24. $category = Category::get($post['category_id']);
  25. $commentlist = Comment::where(['post_id' => $post->id, 'pid' => 0, 'status' => 'normal'])
  26. ->with('sublist')
  27. ->order('id desc')
  28. ->paginate($this->view->config['commentpagesize']);
  29. $post->category = $category;
  30. $this->view->assign("post", $post);
  31. $this->view->assign("category", $category);
  32. $this->view->assign("commentlist", $commentlist);
  33. $this->view->assign("title", isset($post['seotitle']) && $post['seotitle'] ? $post['seotitle'] : $post['title']);
  34. $this->view->assign("keywords", $post['keywords']);
  35. $this->view->assign("description", $post['description']);
  36. return $this->view->fetch('/post');
  37. }
  38. }