初始化


加工POST数据

初始化的时候会加工一下BootstrapTable传过来的数据。


 private function init()
{

   $this->offset = intval(form('offset'));
   $this->limit = intval(form('limit'));
   $this->search = json_decode(form('search'),true);

   if(form('sort') !== ''){
       if(strtoupper(form('order')) === 'ASC') {
           $this->order = form('sort').' ASC';
       }else{
           $this->order = form('sort').' DESC';
       }
   }

   if (!$this->limit || $this->limit > 100) {
       $this->limit  = 10;
   }
}

属性(Property)

offset public
public $offset = 0;
limit public
public $limit = 10;
search public

查询条件

public $search = array();
order public
public $order = null;
filds public
public $filds = '*';
model public
public $model;
join public
public $join;

方法 (Method)


设置搜索条件方法


resetSearchKey($name, $db_col)
public function resetSearchKey($name, $db_col)
{
   if ($name !== $db_col && isset($this->search[$name])) {
       $this->search[$db_col] = $this->search[$name];
       unset($this->search[$name]);
   }
}
setSearch($name, $val)
public function setSearch($name, $val)
{
   $this->search[$name] = $val;
}
defaultOrder($order)
public function defaultOrder($order)
{
   if($this->order === null){
       $this->order = $order;
   }
}
setOrder($order)
public function setOrder($order)
{
   $this->order = $order;
}

数据表的设置方法


setModel($model_name, $join = array())
public function setModel($model_name, $join = array())
{
   $this->model = $this->CI->model($model_name);
   $this->join = $join;
   return $this;
}

执行Model方法


getDataTableData($method = 'get_list',$total_method = 'get_count')

执行获取列表数据和统计数据 get_listget_count方法是 MY_Model里已经定义了方法,除特殊情况之外没必要自己写

返回:

array(
    'rows' => array();
    'total' => int;
);
public function getListData($method = 'getListData',$total_method = 'get_count')
{
   $data['rows'] = $this->model->$method($this->filds, $where, $join, $order, $limit, $offset);

   $data['total'] = $this->model->$total_method( $this->search, $this->join);
   return $data;
}