/** +---------------------------------------------------------- * 根据表单生成查询条件 * 进行列表过滤 +---------------------------------------------------------- * @access protected +---------------------------------------------------------- * @param Model $model 数据对象 * @param HashMap $map 过滤条件 * @param string $sortBy 排序 * @param boolean $asc 是否正序 +---------------------------------------------------------- * @return void +---------------------------------------------------------- * @throws ThinkExecption +---------------------------------------------------------- */ protected function _list($model, $map, $sortBy = '', $asc = false) { //排序字段 默认为主键名 if (!empty($_REQUEST['_order'])) { $order = $_REQUEST['_order']; } else { $order = !empty($sortBy) ? $sortBy : $model->getPk(); } //排序方式默认按照倒序排列 //接受 sost参数 0 表示倒序 非0都 表示正序 if (isset($_REQUEST['_sort'])) { // $sort = $_REQUEST ['_sort'] ? 'asc' : 'desc'; $sort = $_REQUEST['_sort'] == 'asc' ? 'asc' : 'desc'; //zhanghuihua@msn.com } else { $sort = $asc ? 'asc' : 'desc'; } //取得满足条件的记录数 $count = $model->where($map)->count('id'); if ($count > 0) { import("@.ORG.Page"); //创建分页对象 if (!empty($_REQUEST['listRows'])) { $listRows = $_REQUEST['listRows']; } else { $listRows = C("PAGE_LISTROWS"); } $p = new Page($count, $listRows); //分页查询数据 if ($this->isRelation) { $voList = $model->relation($this->isRelation)->where($map)->order("`" . $order . "` " . $sort)->limit($p->firstRow . ',' . $p->listRows)->select(); } else { $voList = $model->where($map)->order("`" . $order . "` " . $sort)->limit($p->firstRow . ',' . $p->listRows)->select(); } //echo $model->getlastsql(); //分页跳转的时候保证查询条件 foreach ($map as $key => $val) { if (!is_array($val)) { $p->parameter .= "{$key}=" . urlencode($val) . "&"; } } //分页显示 $page = $p->show(); //列表排序显示 $sortImg = $sort; //排序图标 $sortAlt = $sort == 'desc' ? '升序排列' : '倒序排列'; //排序提示 $sort = $sort == 'desc' ? 1 : 0; //排序方式 //模板赋值显示 $this->assign('list', $voList); $this->assign('sort', $sort); $this->assign('order', $order); $this->assign('sortImg', $sortImg); $this->assign('sortType', $sortAlt); $this->assign("page", $page); } //zhanghuihua@msn.com $this->assign('totalCount', $count); $this->assign('numPerPage', C('PAGE_LISTROWS')); $this->assign('currentPage', !empty($_REQUEST[C('VAR_PAGE')]) ? $_REQUEST[C('VAR_PAGE')] : 1); cookie('_currentUrl_', __SELF__); return; }
/** +---------------------------------------------------------- * 根据表单生成查询条件 * 进行列表过滤 +---------------------------------------------------------- * @access protected +---------------------------------------------------------- * @param Model $model 数据对象 * @param HashMap $map 过滤条件 * @param string $sortBy 排序 * @param boolean $asc 是否正序 +---------------------------------------------------------- * @return void +---------------------------------------------------------- * @throws ThinkExecption +---------------------------------------------------------- */ protected function _list($model, $map, $sortBy = '', $asc = false) { //排序字段 默认为主键名 $order = $model->getPk() . ' desc'; //取得满足条件的记录数 $count = $model->where($map)->count('id'); if ($count > 0) { //创建分页对象 ,默认10条记录 if (!empty($_REQUEST['listRows'])) { $listRows = $_REQUEST['listRows']; } else { $listRows = '10'; } $p = new Think\Page($count, $listRows); $pageNum = empty($_REQUEST['numPerPage']) ? C('PAGE_LISTROWS') : $_REQUEST['numPerPage']; //分页查询数据 if ($model instanceof RelationModel) { $voList = $model->relation(true)->where($map)->order($order)->limit($pageNum)->page($_REQUEST[C('VAR_PAGE')])->select(); } else { $voList = $model->where($map)->order($order)->limit($pageNum)->page($_REQUEST[C('VAR_PAGE')])->select(); } //分页跳转的时候保证查询条件 foreach ($map as $key => $val) { if (!is_array($val)) { $p->parameter .= "{$key}=" . urlencode($val) . "&"; } } //分页显示 $page = $p->show(); //列表排序显示 $sortImg = $sort; //排序图标 $sortAlt = $sort == 'desc' ? '升序排列' : '倒序排列'; //排序提示 $sort = $sort == 'desc' ? 1 : 0; //排序方式 //模板赋值显示 $this->assign('list', $voList); $this->assign('sort', $sort); $this->assign('order', $order); $this->assign('sortImg', $sortImg); $this->assign('sortType', $sortAlt); $this->assign("page", $page); } //囚鸟先生 $this->assign('totalCount', $count); $pageNum = empty($_REQUEST['numPerPage']) ? C('PAGE_LISTROWS') : $_REQUEST['numPerPage']; $this->assign('numPerPage', $pageNum); //每页显示多少条 $this->assign('currentPage', !empty($_REQUEST[C('VAR_PAGE')]) ? $_REQUEST[C('VAR_PAGE')] : 1); cookie('_currentUrl_', __SELF__); return; }