コード例 #1
0
 /**
  * 列表页
  */
 public function index()
 {
     $id = (int) I('get.id');
     $cate = M('cate')->order('sort')->select();
     $cids = \Admin\Common\Category::getChildsId($cate, $id);
     $cids[] = $id;
     $where = array('cid' => array('IN', $cids), 'del' => 0);
     // 获取总文章数
     $count = M('blog')->where($where)->count();
     // 实例化分页类
     $page = new \Think\Page($count, 5);
     // 设置分页链接样式
     $page->setConfig('prev', '<');
     $page->setConfig('next', '>');
     $limit = $page->firstRow . ',' . $page->listRows;
     $cate = D('BlogView')->getAll($where, $limit);
     // 显示分页
     $page = $page->show();
     // 解析并重新整理分页URL
     $page = trimPageUrl($page);
     // 转换每一篇文章video字段的HTML实体用于输出
     foreach ($cate as $key => $value) {
         $cate[$key]['video'] = htmlspecialchars_decode($cate[$key]['video']);
         $cate[$key]['image'] = __APP__ . '/' . trim($cate[$key]['image'], '@');
     }
     $this->assign('cate', $cate);
     $this->assign('page', $page);
     $this->display();
 }
コード例 #2
0
 /**
  * 首页
  */
 public function index()
 {
     //p(C('TMPL_EXCEPTION_FILE').'111');exit();
     if (!($list = S('index_list'))) {
         //判断缓存
         // 按分类排布
         // $list = M('cate')->where(array('pid' => 0))->order('sort')->select();
         // $cate = M('cate')->order('sort')->select();
         // $db = M('blog');
         // $field = (array('id','title','image','video','time'));
         // foreach ($list as $k => $v){
         //     $cids = \Admin\Common\Category::getChildsId($cate, $v['id']);
         //     $cids[] = $v['id'];
         //     $where = array('cid'=>array('IN',$cids));
         //     $list[$k]['blog'] = $db->field($field)->where($where)->order('time DESC')->select();
         // }
         // 获取总文章数
         $count = M('blog')->where(array('del' => 0))->count();
         // 实例化分页类
         $page = new \Think\Page($count, 5);
         // 设置分页链接样式
         $page->setConfig('theme', '<div class="col-md-5 pull-left">%UP_PAGE%</div> <div class="col-md-5 col-md-offset-2 pull-right">%DOWN_PAGE%</div>');
         $page->setConfig('prev', '<');
         $page->setConfig('next', '>');
         $field = array('id', 'title', 'image', 'summary', 'time');
         $list = M('blog')->field($field)->where(array('del' => 0))->order('time DESC')->limit($page->firstRow . ',' . $page->listRows)->select();
         // 显示分页
         $page = $page->show();
         // 解析并重新整理分页URL
         $page = trimPageUrl($page);
         // 转换每一篇文章video字段的HTML实体用于输出
         // 生成image字段的URL地址
         foreach ($list as $key => $value) {
             $list[$key]['video'] = htmlspecialchars_decode($list[$key]['video']);
             $list[$key]['image'] = __APP__ . '/' . trim($list[$key]['image'], '@');
         }
         // 缓存
         // S("index_list",$list,10);
     }
     $this->assign('cate', $list);
     $this->assign('page', $page);
     $this->display();
 }