thinkphp 带检索参数分页

2021-07-19 22:05

阅读:428

标签:splay   xtend   文件   显示   function   hid   isp   use   dmi   

模板文件中,提交搜索内容要用get方法,同时设置g、m、c隐藏域。

form action="{:U(‘Sck/qbscHjsc‘)}" method="get">
    table class="search-tab">
    tr>
                    input type="hidden" name="g" value="">
                    input type="hidden" name="m" value="">
                    input type="hidden" name="a" value="">
                    th width="120">素材名称:th>
        td>
        input class="common-text" name="mingcheng" size="20" value="" type="text">
        td>

 

controller中处理

// 素材库 环境素材检索
public function qbscHjsc(){

    $where = ‘ fenxiang=1 ‘;
    // 查询参数
    if(I(‘request.leixing‘)!=‘‘){
        if(I(‘request.mingcheng‘) != ‘‘){
            $where .= ‘ and mingcheng like \‘%‘.I(‘request.mingcheng‘).‘%\‘ ‘;
        }
    } 

    ...

    $sck_model=M("Kczz_sck");
    
    $count=$sck_model->where($where)->count();
    $page = $this->page($count, 10);

    $list = $sck_model
    ->where($where)
    ->order("id desc")
    ->limit($page->firstRow . ‘,‘ . $page->listRows)
    ->select();

    $this->assign(‘list‘, $list);
    $this->assign(‘page‘, $page->show(‘Admin‘));

    $this->display();
}

 

如果是前台的controller,需要自己导入page类

php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function sck(){

        $where = ‘ fenxiang=1 ‘;
        // 查询参数
        if(I(‘request.leixing‘)!=‘‘){
            if(I(‘request.mingcheng‘) != ‘‘){
                $where .= ‘ and mingcheng like \‘%‘.I(‘request.mingcheng‘).‘%\‘ ‘;
            }
        } 

        ...

        $sck_model=M("Kczz_sck");
        import(‘ORG.Util.Page‘);    // 导入分页类

        $count=$sck_model->where($where)->count();
            $Page = new \Think\Page($count,5);
        $show = $Page->show();    // 分页显示输出

        $list = $sck_model
        ->where($where)
        ->order("id desc")
        ->limit($Page->firstRow . ‘,‘ . $Page->listRows)
        ->select();

        $this->assign(‘list‘, $list);
        $this->assign(‘page‘, $show);

        $this->display();
    }
}

 

模板处翻页代码

div class="list-page"> {$page}div>

 

thinkphp 带检索参数分页

标签:splay   xtend   文件   显示   function   hid   isp   use   dmi   

原文地址:http://www.cnblogs.com/dwj192/p/7057992.html


评论


亲,登录后才可以留言!