Example #1
0
 public function showAction(Post $postModel)
 {
     $posts = $postModel->getRecentlyPosts(1, 20);
     $feed = new Feed();
     $channel = new Channel();
     $channel->title('Aicode')->description('爱生活,爱代码')->url('http://aicode.cc')->lastBuildDate($posts['data'][0]['publish_date'])->appendTo($feed);
     foreach ($posts['data'] as $art) {
         $item = new Item();
         $item->title($art['title'])->description('<p><img src="' . $art['feature_img'] . '" /></p>' . (new \Parsedown())->parse($art['content']))->url('http://aicode.cc/article/' . $art['id'] . '.html')->pubDate($art['publish_date'])->guid('http://aicode.cc/article/' . $art['id'] . '.html')->appendTo($channel);
     }
     header('Content-Type:text/xml; charset=utf-8');
     return $feed->render();
 }
Example #2
0
 /**
  * 首页
  *
  * @param Request $request
  * @param Post $postModel
  *
  * @return string
  */
 public function indexAction(Request $request, Post $postModel)
 {
     $current = intval($request->get('page', 1));
     $key = "list_{$current}";
     $html = $this->getCache()->get($key);
     if (false === $html) {
         $posts = $postModel->getRecentlyPosts($current, 10);
         $this->assign('posts', $posts['data']);
         $this->assign('page', $posts['page']);
         $this->assign('parsedown', new \Parsedown());
         $this->assign('catModel', new Category());
         $html = $this->view('index')->render();
         $this->getCache()->set($key, $html);
     }
     return $html;
 }