Index.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace addons\blog\controller;
  3. use addons\blog\model\Post;
  4. use think\Paginator;
  5. /**
  6. * 博客首页
  7. */
  8. class Index extends Base
  9. {
  10. public function index()
  11. {
  12. $postlist = Post::where(['status' => 'normal'])
  13. ->with('category')
  14. ->order('weigh desc,id desc')
  15. ->paginate($this->view->config['listpagesize'], false, ['type' => '\\addons\\blog\\library\\Bootstrap']);
  16. $page = Paginator::getCurrentPage();
  17. $urls = $postlist->getUrlRange($page - 1, $page + 1);
  18. $prevurl = $page == 1 ? '' : array_shift($urls);
  19. $nexturl = $page == $postlist->lastPage() ? '' : array_pop($urls);
  20. $this->view->assign("postlist", $postlist);
  21. $this->view->assign('prevurl', $prevurl);
  22. $this->view->assign('nexturl', $nexturl);
  23. if ($this->request->isAjax()) {
  24. return $this->view->fetch('/common/postlist');
  25. }
  26. $config = get_addon_config('blog');
  27. $this->view->assign('keywords', $config['keywords']);
  28. $this->view->assign('description', $config['description']);
  29. return $this->view->fetch('/index');
  30. }
  31. }