/** * 列表处理 * * @param obj $model 实例化后的模型 * @param array $map 条件数据 * @param string $sort_by 排序字段 * @param string $order_by 排序方法 * @param string $field_list 显示字段 * @param intval $pagesize 每页数据行数 */ protected function _list($model, $map = array(), $sort_by = '', $order_by = '', $field_list = '*', $pagesize = 50) { //排序 $mod_pk = $model->getPk(); if ($this->_request("sort", 'trim')) { $sort = $this->_request("sort", 'trim'); } else { if (!empty($sort_by)) { $sort = $sort_by; } else { if ($this->sort) { $sort = $this->sort; } else { $sort = $mod_pk; } } } if ($this->_request("order", 'trim')) { $order = $this->_request("order", 'trim'); } else { if (!empty($order_by)) { $order = $order_by; } else { if ($this->order) { $order = $this->order; } else { $order = 'DESC'; } } } if ($pagesize) { $count = $model->where($map)->count($mod_pk); $pager = new Page($count, $pagesize); } $select = $model->field($field_list)->where($map)->order($sort . ' ' . $order); $this->list_relation && $select->relation(true); if ($pagesize) { $select->limit($pager->firstRow . ',' . $pager->listRows); $page = $pager->show(); $this->assign("page", $page); } $list = $select->select(); $this->assign('list', $list); $this->assign('list_table', true); }
/** * 列表处理 * * @param obj $model 实例化后的模型 * @param array $map 条件数据 * @param string $sort_by 排序字段 * @param string $order_by 排序方法 * @param string $field_list 显示字段 * @param intval $pagesize 每页数据行数 */ protected function _list($model, $map = array(), $sort_by = '', $order_by = '', $field_list = '*', $pagesize = 20) { //排序 $mod_pk = $model->getPk(); if (input("request.sort", 'trim')) { $sort = input("request.sort", 'trim'); } else { if (!empty($sort_by)) { $sort = $sort_by; } else { if ($this->sort) { $sort = $this->sort; } else { $sort = $mod_pk; } } } if (input("request.order", 'trim')) { $order = input("request.order", 'trim'); } else { if (!empty($order_by)) { $order = $order_by; } else { if ($this->order) { $order = $this->order; } else { $order = 'DESC'; } } } //如果需要分页 if ($pagesize) { $count = $model->where($map)->count($mod_pk); $pager = new \Common\ORG\Page($count, $pagesize); } $select = $model->field($field_list)->where($map)->order($sort . ' ' . $order); // echo M()->getLastSql(); $this->list_relation && $select->relation(true); if ($pagesize) { $select->limit($pager->firstRow . ',' . $pager->listRows); $page = $pager->show(); $this->assign("page", $page); } $list = $select->select(); foreach ($list as $key => $value) { $catename = M('user_category')->field('name')->where(array('id' => $value['uid']))->find(); $value['cname'] = $catename['name']; $list[$key] = $value; //重复值list } //dump($list); $this->assign('list', $list); $this->assign('list_table', true); }
/** * 列表处理 * * @param obj $model 实例化后的模型 * @param array $map 条件数据 * @param string $sort_by 排序字段 * @param string $order_by 排序方法 * @param string $field_list 显示字段 * @param intval $pagesize 每页数据行数 */ protected function _list($model, $map = array(), $sort_by = '', $order_by = '', $field_list = '*', $pagesize = 10) { //排序 $mod_pk = $model->getPk(); if (i("sort", '', 'trim')) { $sort = i("sort", '', 'trim'); } else { if (!empty($sort_by)) { $sort = $sort_by; } else { if ($this->sort) { $sort = $this->sort; } else { $sort = $mod_pk; } } } if (i("order", '', 'trim')) { $order = i("order", '', 'trim'); } else { if (!empty($order_by)) { $order = $order_by; } else { if ($this->order) { $order = $this->order; } else { $order = 'DESC'; } } } /** * 如果有where 存在,并且形式是数组,则合并条件 */ if ($this->where && is_array($this->where)) { //dump($this->where); $map = array_merge($this->where, $map); } // dump(property_exists(CONTROLLER_NAME."Action","where")); /** * 如果设定全局翻页变量,则覆盖原来的默认值。 */ $pagesize = property_exists($this, "pagesize") ? $this->pagesize : $pagesize; // dump(property_exists($this,"pagesize")); //如果需要分页 if ($pagesize) { $count = $model->where($map)->count($mod_pk); import('Page', APP_PATH . '/Lib'); $pager = new \Page($count, $pagesize); } $select = $model->field($field_list)->where($map)->order($sort . ' ' . $order); $this->list_relation && $select->relation(true); if ($pagesize) { $select->limit($pager->firstRow . ',' . $pager->listRows); $page = $pager->show(); $this->assign("page", $page); } $list = $select->select(); // dump($select->getLastSql());//exit(); // print_r($list);exit(); /** * 如果需要处理数据则处理数据以后再返回 */ if (method_exists($this, '_before_list')) { $list = $this->_before_list($list); } $p = i('get.p', 1, 'intval'); $this->assign('p', $p); $this->assign('list', $list); $this->assign('list_table', true); return $list; }
/** * 列表处理 * * @param obj $model 实例化后的模型 * @param array $map 条件数据 * @param string $sort_by 排序字段 * @param string $order_by 排序方法 * @param string $field_list 显示字段 * @param intval $pagesize 每页数据行数 */ protected function _list($model, $map = array(), $sort_by = '', $order_by = '', $field_list = '*', $pagesize = 20) { //排序 $mod_pk = $model->getPk(); if ($this->_request("sort", 'trim')) { $sort = $this->_request("sort", 'trim'); } else { if (!empty($sort_by)) { $sort = $sort_by; } else { if ($this->sort) { $sort = $this->sort; } else { $sort = $mod_pk; } } } if ($this->_request("order", 'trim')) { $order = $this->_request("order", 'trim'); } else { if (!empty($order_by)) { $order = $order_by; } else { if ($this->order) { $order = $this->order; } else { $order = 'DESC'; } } } //如果需要分页 if ($pagesize) { $count = $model->where($map)->count($mod_pk); $pager = new Page($count, $pagesize); } $select = $model->field($field_list)->where($map)->order($sort . ' ' . $order); $this->list_relation && $select->relation(true); if ($pagesize) { $select->limit($pager->firstRow . ',' . $pager->listRows); $page = $pager->show(); $this->assign("page", $page); } $list = $select->select(); foreach ($list as &$item) { switch ($item['color']) { case '1': $item['color'] = '黑'; break; case '2': $item['color'] = '红'; break; case '3': $item['color'] = '绿'; break; case '4': $item['color'] = '蓝'; break; default: $item['color'] = '黑'; break; } } $this->assign('list', $list); $this->assign('list_table', true); }
/** * 列表处理 * * @param obj $model 实例化后的模型 * @param array $map 条件数据 * @param string $sort_by 排序字段 * @param string $order_by 排序方法 * @param string $field_list 显示字段 * @param intval $pagesize 每页数据行数 */ protected function _list($model, $map = array(), $sort_by = '', $order_by = '', $field_list = '*', $page, $pagesize = 10) { //排序 $mod_pk = $model->getPk(); if ($this->_request("sort", 'trim')) { $sort = $this->_request("sort", 'trim'); } else { if (!empty($sort_by)) { $sort = $sort_by; } else { if ($this->sort) { $sort = $this->sort; } else { $sort = $mod_pk; } } } if ($this->_request("order", 'trim')) { $order = $this->_request("order", 'trim'); } else { if (!empty($order_by)) { $order = $order_by; } else { if ($this->order) { $order = $this->order; } else { $order = 'ASC'; } } } if ($page) { $count = $model->where($map)->count($mod_pk); $appjson['count'] = intval($count); $pagecount = ceil($count / $pagesize); $start = ($page - 1) * $pagesize; $appjson['pagecount'] = $pagecount; } $select = $model->field($field_list)->where($map)->order($sort . ' ' . $order); $this->list_relation && $select->relation(true); if ($page) { $select->limit($start . ',' . $pagesize); } $list = $select->select(); $appjson['list'] = $list; return $appjson; }