今晚我繼續這個項目的前臺開發,把前臺的作出來了,如今項目進行一個收尾工做了,還有欄目頁和一個文章頁的開發,作完這兩個算是完成了。說到這裏感受有點鬆懈了,把剩下兩個功能頁面作完在吹吧,先看看今天弄的代碼吧!php
前臺公共控制器:html
<?php namespace Home\Controller; use Think\Controller; class CommonController extends Controller { public function __construct() { header('Content-type:text/html;charset=utf-8'); parent::__construct(); } /** *@return 獲取排序數據 */ public function getRank() { $conds['status']=1; $news=D('News')->getRank($conds, 10); return $news; } public function error($message = '') { $message=$message?$message:'系統發生錯誤'; $this->assign('message', $message); $this->display('Index/error'); } }
前臺首頁控制器:git
<?php namespace Home\Controller; use Think\Controller; class IndexController extends CommonController { public function index($type = '') { //獲取排序數據 $rankNews=$this->getRank(); //獲取首頁大圖數據 $topPicNews=D('PositionContent')->select( array( 'status'=>1, 'position_id'=>2 ), 1 ); // 首頁小圖推薦 $topSmailNews=D('PositionContent')->select( array('status'=>1,'position_id'=>3), 3 ); $listNews=D('News')->select(array('status'=>1,'thumb'=>array('neq','')), 30); $addNews=D('PositionContent')->select(array('status'=>1,'position_id'=>5), 2); $this->assign('result', array( 'topPicNews'=>$topPicNews, 'topSmailNews'=>$topSmailNews, 'listNews'=>$listNews, 'advNews'=>$advNews, 'rankNews'=>$rankNews, 'catId'=>0, )); /** *生成靜態頁面 */ if ($type=='buildHtml') { $this->buildHtml('index', HTML_PATH, 'Index/index'); } else { $this->display(); } } public function build_html() { $this->index('buildHtml'); return jsonResult(1, '首頁緩存生成成功'); } public function crontab_build_html() { if (APP_CRONTAB != 1) { die('the_file_must_exec_crontab'); } $result=D('Basic')->select(); if (!$result['cacheindex']) { die('系統沒有設置開啓自動生成首頁緩存的內容'); } $this->index('buildHtml'); } public function getCount() { if (!$_POST) { return jsonResult(0, '沒有任何內容'); } $newsIds=array_unique($_POST); try { $list=D('News')->getNewsByNewsIdIn($newsIds); } catch (Exception $e) { return jsonResult(0, $e->getMessage()); } if (!$list) { return jsonResult(0, 'notdata'); } $data=array(); foreach ($list as $k => $v) { $data[$v['news_id']]=$v['count']; } return jsonResult(1, 'success', $data); } }
今天就寫了這兩個類,其實已經不難了,都是那麼兩板斧了。今天就到這睡覺了!github
源碼地址:https://github.com/YoZiLin/TP-CMSjson