首页 技术 正文
技术 2022年11月7日
0 收藏 586 点赞 743 浏览 2038 个字

  今晚我继续这个项目的前台开发,把前台的做出来了,现在项目进行一个收尾工作了,还有栏目页和一个文章页的开发,做完这两个算是完成了。说到这里感觉有点松懈了,把剩下两个功能页面做完在吹吧,先看看今天弄的代码吧!

  前台公共控制器:

<?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

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,112
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,585
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,431
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,203
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,838
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,922