/** * 单元 显示首页 */ function index() { import('ORG.Util.Page'); $sections = new SectionModel(); //判断是否有搜索 $keyword = trim($_POST['keyword']); /* $ftype = trim($_POST['ftype']); if(!empty($keyword) && !empty($ftype)){ //如果查询的是发布字段(因为发布字段和排序都是以整数来排列的) if ($ftype == 'published' || $ftype == 'order' || $ftype == 'id'){ $where[$ftype] = array('eq',$keyword); }else{ $where[$ftype] = array('like','%'.$keyword.'%'); } } */ if (is_numeric($keyword)) { $where['id'] = array('eq', $keyword); } else { $where['title'] = array('like', '%' . $keyword . '%'); } //切换状态 $change_pub = trim($_POST['change_published']); if ($change_pub) { $where['published'] = array('eq', $change_pub); } //传值在前台判断 $this->assign('change_pub', $change_pub); //得到分页需要的总文章数 $count = $sections->where($where)->count(); $page = new Page($count, C('PAGESIZE')); $show = $page->show(); $this->assign("show", $show); //得到文章数据 $list = $sections->where($where)->order('id DESC')->limit($page->firstRow . ',' . $page->listRows)->select(); $this->assign('slist', $list); //分配配置中的每页显示多少文章到前台 $this->assign('pagesize', C('PAGESIZE')); $this->display(); }