[php]
/**
+———————————————————-
* 根据表单生成查询条件
* 进行列表过滤
+———————————————————-
* @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,$count=-1 ) {
//排序字段 默认为主键名
if (isset ( $_REQUEST [‘_order’] )) {
$order = $_REQUEST [‘_order’];
} else {
$order = ! empty ( $sortBy ) ? $sortBy : $model->getPk ();
}
//排序方式默认按照倒序排列
//接受 sost参数 0 表示倒序 非0都 表示正序
if (isset ( $_REQUEST [‘_sort’] )) {
$sort = $_REQUEST [‘_sort’] ? ‘asc’ : ‘desc’;
} else {
$sort = $asc ? ‘asc’ : ‘desc’;
}
//取得满足条件的记录数
if($count==-1)
$count = $model->where ( $map )->count ();
if ($count > 0) {
//创建分页对象
if (! empty ( $_REQUEST [‘listRows’] )) {
$listRows = $_REQUEST [‘listRows’];
} else {
$listRows = ”;
}
$p = new Page ( $count, $listRows );
//分页查询数据
$voList = $model->where($map)->order( "`" . $order . "` " . $sort)->limit($p->firstRow . ‘,’ . $p->listRows)->findAll ( );
// 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’ ? l("ASC_SORT") : l("DESC_SORT"); //排序提示
$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 ( "nowPage",$p->nowPage);
}
return;
}
调用
//定义条件
$map[DB_PREFIX.’user.is_delete’] = 0;
if(intval($_REQUEST[‘group_id’])>0)
{
$map[DB_PREFIX.’user.group_id’] = intval($_REQUEST[‘group_id’]);
}
if(strim($_REQUEST[‘user_name’])!=”)
{
$map[DB_PREFIX.’user.user_name’] = array(‘like’,"%".strim($_REQUEST[‘user_name’])."%");
}
if(strim($_REQUEST[’email’])!=”)
{
$map[DB_PREFIX.’user.email’] = array(‘eq’,strim($_REQUEST[’email’]));
}
if(strim($_REQUEST[‘mobile’])!=”)
{
$map[DB_PREFIX.’user.mobile’] = array(‘eq’,strim($_REQUEST[‘mobile’]));
}
if(strim($_REQUEST[‘pid_name’])!=”)
{
$pid = M("User")->where("user_name=’".strim($_REQUEST[‘pid_name’])."’")->getField("id");
$map[DB_PREFIX.’user.pid’] = $pid;
}
if (method_exists ( $this, ‘_filter’ )) {
$this->_filter ( $map );
}
$name=$this->getActionName();
$model = D ($name);
if (! empty ( $model )) {
$this->_list ( $model, $map );
}
$this->display ();
[/php]
[html][/html]
id=”dataTable”
style=”dataTable”
name=”user”
checkbox=”true”
action=”true”
datasource=”list”
show=”id:{%ID}|50px,user_name:{%USER_NAME}:edit,email:{%USER_EMAIL},mobile:{%USER_MOBILE},is_robot|get_is_robot:机器人,money|format_price:{%USER_MONEY},score|format_score:会员代金券,pid|get_referrals_name:{%REFERRALS_NAME},create_time|to_date:注册时间,login_time|to_date:{%LOGIN_TIME},is_effect|get_is_effect=$user[‘id’]:{%IS_EFFECT}”
actionlist=”edit:{%EDIT}, del:{%DEL}, account:{%USER_ACCOUNT},account_detail:{%USER_ACCOUNT_DETAIL}” />
[html][/html]