前端到后台ThinkPHP开发整站(7)
今晚我继续这个项目的前台开发,把前台的做出来了,现在项目进行一个收尾工作了,还有栏目页和一个文章页的开发,做完这两个算是完成了。说到这里感觉有点松懈了,把剩下两个功能页面做完在吹吧,先看看今天弄的代码吧!
前台公共控制器:
<?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'); } }
前台首页控制器:
<?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); } }
今天就写了这两个类,其实已经不难了,都是那么两板斧了。今天就到这睡觉了!
源码地址:https://github.com/YoZiLin/TP-CMS