xiaofeng028

ThinkPHP 分页可以很容易的实现对不固定查询参数的支持。具体实现是给分页类的 parameter 属性赋值或者直接实例化分页类时传入查询参数。下面以例子来说明。
parameter 属性赋值

例如要检索用户表中状态为 1 (status=1) 并且电子包含 163 的用户,当提交表单时(注意表单是 GET 方式提交),形成的 URL 地址大致如下:

public function search(){

    $Dao = M("User");

    // 构造查询条件

    $condition[\'status\'] = $_GET[\'status\'];

    $condition[\'email\'] = array(\'like\',"%".$_GET[\'email\']."%");

    // 计算总数

    $count = $Dao->where($condition)->count();

    // 导入分页类

    import("ORG.Util.Page");

    // 实例化分页类

   $p = new Page($count, 10);

    // 获取查询参数

    $map[\'status\'] = $_GET[\'status\'];

    $map[\'email\'] = $_GET[\'email\'];

    foreach($map as $key=>$val) { 

        $p->parameter .= "$key=".urlencode($val)."&"; 

    }

    // 分页显示输出

    $page = $p->show();

 

    // 当前页数据查询

    $list = $Dao->where($condition)->order(\'uid ASC\')->limit($p->firstRow.\',\'.$p->listRows)->select();

 

    // 赋值赋值

    $this->assign(\'page\', $page);

    $this->assign(\'list\', $list);


    $this->display();

}

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-07-27
  • 2022-12-23
  • 2022-12-23
  • 2021-11-14
  • 2021-12-03
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-12
相关资源
相似解决方案