public function index() { $model = new ArticleCategoryViewModel(); $count = $model->count(); $page = new Page($count); $show = $page->show(); $list = $model->order('articleId DESC')->limit($page->firstRow . ',' . $page->listRows)->field('articleId,title,description,hits,createdAt,updateAt,status,sort,name,categoryId')->select(); $this->assign('list', $list); $this->assign('page', $show); $this->display(); }
public function article($id) { $model = new ArticleCategoryViewModel(); $article = $model->where(array('articleId' => $id))->find(); if (empty($article)) { $this->error('文章不存在'); } $isHits = S('article-view-' . $id . '-' . get_client_ip()); if (!$isHits) { $model->where(array('articleId' => $id))->setInc('hits'); S('article-view-' . $id . '-' . get_client_ip(), 1, 600); $article['hits']++; } //评论 $commentModel = new Model('Comment'); $comments = $commentModel->where(array('articleId' => $id))->limit(30)->order('commentId DESC')->select(); $this->assign('article', $article); $this->assign('comments', $comments); $this->display(); }