/**
  * 删除分类操作
  * @return void [description]
  */
 public function deleteCate()
 {
     $id = (int) I('get.id');
     //判断如果有下级分类,则连同下级分类一起删除
     if (M('cate')->where('pid=' . $id . '')->select()) {
         $cate = M('cate')->order('sort DESC')->select();
         // 从数据库取得所有分类
         $condition = \Admin\Common\Category::getChildsId($cate, $id);
         // 取得传入父分类的所有子分类
         $where['id'] = array('in', $condition);
         // 删除分类及其所有子分类
         if (M('cate')->where($where)->delete()) {
             $this->success('删除成功', U('Category/index'));
         } else {
             $this->error('删除失败');
         }
     } else {
         // 删除分类
         if (M('cate')->where('id=' . $id . '')->delete()) {
             $this->success('删除成功', U('Category/index'));
         } else {
             $this->error('删除失败');
         }
     }
 }
Example #2
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();
 }
Example #3
0
 /**
  * 显示文章页面
  */
 public function index()
 {
     if ((int) I("get.id") <= M('blog')->max('id') && (int) I("get.id") > 0) {
         $id = (int) I('get.id');
         $field = array('id', 'title', 'time', 'content', 'cid');
         $blog = M('blog')->field($field)->find($id);
         $blog['content'] = htmlspecialchars_decode($blog['content']);
         $this->blog = $blog;
         $cid = $this->blog['cid'];
         $cate = M('cate')->order('sort')->select();
         $this->parent = \Admin\Common\Category::getParents($cate, $cid);
         $this->display();
     } else {
         $this->error('文章不存在!');
     }
 }
Example #4
0
 /**
  * 修改文章页面
  */
 public function showModify()
 {
     $id = I('get.id');
     $blog = M('blog')->where('id=' . $id)->select();
     // 所有分类
     $cate = M('cate')->order('sort')->select();
     $cate = \Admin\Common\Category::unlimitedForLevel($cate);
     // 所有属性
     $attr = M('attr')->select();
     // 将时间戳转换为易读的时间
     $blog[0]['time'] = date('Y-m-d H:i:s', $blog[0]['time']);
     // 将本文属性加入到数组中
     $blog[0]['attr'] = M('blog_attr')->where('bid=' . $id)->field('aid')->select();
     $blog[0]['attr'] = \myFunction\multiArray_combine($blog[0]['attr']);
     $this->assign("cate", $cate);
     $this->assign("attr", $attr);
     $this->assign("modify", $blog[0]);
     $this->display("Blog:blog");
 }