Archive.php 762 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace addons\blog\controller;
  3. use addons\blog\model\Post;
  4. /**
  5. * 博客归档
  6. */
  7. class Archive extends Base
  8. {
  9. public function index()
  10. {
  11. $postlist = Post::where('status', 'normal')
  12. ->with(['category'])
  13. ->field('id,title,createtime,diyname,category_id')
  14. ->order("createtime", "desc")
  15. ->cache(3600 * 365)
  16. ->select();
  17. $yearlist = [];
  18. foreach ($postlist as $k => $v) {
  19. $yearlist[date("Y", $v['createtime'])][] = ['id' => $v['id'], 'title' => $v['title'], 'url' => $v['url']];
  20. }
  21. $this->view->assign('yearlist', $yearlist);
  22. $this->view->assign('title', '日志归档');
  23. return $this->view->fetch('/archive');
  24. }
  25. }