久違了,今天終於抽空把最後的寫完了,這是這個項目的最後一篇文章了,把前臺的欄目控制器和文章內容控制器的功能實現了。php
欄目控制器:html
<?php namespace Home\Controller; use Think\Controller; class CatController extends CommonController{ public function index(){ $id=intval($_GET['id']); if(!$id){ return $this->error('ID不存在'); } $nav=D('Menu')->find($id); if(!$nav || $nav['status']!=1){ return $this->error('欄目id不存在或者狀態不爲正常'); } $advNews=D('PositionContent')->select(array('status'=>1,'position_id'=>5),2); $rankNews=$this->getRank(); $page=$_REQUEST['p']?$_REQUEST['p']:1; $pageSize=20; $conds=array( 'status'=>1, 'thumb'=>array('neq',''), 'catid'=>$id ); $news=D('News')->getNews($conds,$page,$pageSize); $count=D('News')->getNewsCount($conds); $res=new \Think\Page($count,$pageSize); $pageres=$res->show(); $this->assign('result',array( 'advNews'=>$advNews, 'rankNews'=>$rankNews, 'catId'=>$id, 'listNews'=>$news, 'pageres'=>$pageres )); $this->display(); } } ?>
文章內容控制器:git
<?php namespace Home\Controller; use Think\Controller; class DetailController extends CommonController{ public function index(){ $id=intval($_GET['id']); if(!$id || $id<0){ return $this->error('ID不合法'); } $news=D('News')->find($id); if(!$news || $news['status']!=1){ return $this->error('ID不存在或者資訊被關閉'); } $count=intval($news['count'])+1; D('News')->updateCount($id,$count); $content=D('NewsContent')->find($id); $news['content']=\htmlspecialchars_decode($content['content']); $advNews=D('PositionContent')->select(array('status'=>1,'position_id'=>5),2); $rankNews=$this->getRank(); $this->assign('result',array( 'rankNews'=>$rankNews, 'advNews'=>$advNews, 'catId'=>$news['catid'], 'news'=>$news )); $this->display('Detail/index'); } public function view(){ if(!getLoginUsername()){ $this->error('您沒有權限訪問該頁面'); } $this->index(); } } ?>
終於堅持的把該項目作完了,這個項目我也是上淘寶買的教程,邊學邊作的!可能還會有不少BUG和可改善的地方,往後慢慢檢查做修改。github
源碼地址:https://github.com/YoZiLin/TP-CMSthis