標籤:http common cond public post namespace extend 推薦 ade
今晚我繼續這個項目的前台開發,把前台的做出來了,現在項目進行一個收尾工作了,還有欄目頁和一個文章頁的開發,做完這兩個算是完成了。說到這裡感覺有點鬆懈了,把剩下兩個功能頁面做完在吹吧,先看看今天弄的代碼吧!
前台公用控制器:
<?phpnamespace 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‘); }}
前台首頁控制器:
<?phpnamespace 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); }}
今天就寫了這兩個類,其實已經不難了,都是那麼兩板斧了。今天就到這睡覺了!
源碼地址:https://github.com/YoZiLin/TP-CMS
前端到後台ThinkPHP開發整站(7)