模板文件中,提交搜索内容要用get方法,同时设置g、m、c隐藏域。
<form action="{:U(‘Sck/qbscHjsc‘)}" method="get"> <table class="search-tab"> <tr> <input type="hidden" name="g" value="<?php echo MODULE_NAME; ?>"> <input type="hidden" name="m" value="<?php echo CONTROLLER_NAME; ?>"> <input type="hidden" name="a" value="<?php echo ACTION_NAME; ?>"> <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>
时间: 2024-10-12 19:40:21