[php]代码库
<?php
class IndexAction extends Action{
public function index(){
if (!$MainList=S('main_list')){ //判断是否已经有缓存
$MainList = M('cate')->where(array('pid' => 0 ))->order('sort')->select();
import('Class.Category',APP_PATH);
$cate = M('cate')->order('sort')->select();
$db = M('blog');
$field = array('id','title','time');
foreach ($MainList as $k =>$v) {
$cids =Category::getChildrenId($cate,$v['id']);
$cids[] = $v['id'];
$where = array('del' => 0, 'cid' => array('IN',$cids));
$MainList[$k]['blog'] = $db->field($field)->where($where)->limit(20)->order('time DESC')->select();
}
//设置缓存
S('main_list', $MainList, 60, 'File');//main_list缓存名称,$MainList,缓存数据,60缓存时间,
}
$this->cate = $MainList;
$this->display('');
}
}
?>