?php
namespace Home\Controller;
use Think\Controller;
class BaseController extends Controller {
/**
* 基礎(chǔ)分頁的相同代碼封裝,使前臺的代碼更少
* @param $count 要分頁的總記錄數(shù)
* @param int $pagesize 每頁查詢條數(shù)
* @return \Think\Page
*/
function getpage($count, $pagesize = 20,$waps) {
$Page = new \Think\Page($count,$pagesize,$waps);
$Page->rollPage = 5;
$Page->setConfig('header', 'li class="rows">第b>%NOW_PAGE%/b>頁/共b>%TOTAL_PAGE%/b>頁/li>');
$Page->setConfig('prev', '上一頁');
$Page->setConfig('next', '下一頁');
$Page->setConfig('last', '末頁');
$Page->setConfig('first', '首頁');
$Page->setConfig('theme', '%FIRST%%UP_PAGE%%LINK_PAGE%%DOWN_PAGE%%END%%HEADER%');
$Page->lastSuffix = false;//最后一頁不顯示為總頁數(shù)
return $Page;
}
/**
* @param $model 模型
* @param $map where條件
* @param $find 0 select 1=find 2=關(guān)聯(lián)表
* @return $list 數(shù)組
*/
function _select($model,$map,$order='',$field="",$find="0",$limit=20,$join,$param){
$waps = $param;
if(empty($model) empty($map)){
$this->list = array();
}else{
if($find == 0){
$count = $model->where($map)->count();
$Page = $this->getpage($count,$limit,$waps);
if($Page->firstRow 0){
$Page->firstRow = 0;
}
if($order != ""){
$this->list = $model->field($field)->where($map)->order($order)->limit($Page->firstRow. ',' . $Page->listRows)->select();
}else{
$this->list = $model->field($field)->where($map)->limit($Page->firstRow. ',' . $Page->listRows)->select();
}
$this->page = $Page->show();
}else if($find == 1){
$this->list = $model->field($field)->where($map)->find();
}else if($find == 3){
$count = $model->alias("t1")->join($join)->where($map)->count();
$Page = $this->getpage($count,$limit,$waps);
if($Page->firstRow 0){
$Page->firstRow = 0;
}
if($order != ""){
$this->list = $model->alias("t1")->join($join)->field($field)->where($map)->order($order)->limit($Page->firstRow. ',' . $Page->listRows)->select();
}else{
$this->list = $model->alias("t1")->join($join)->field($field)->where($map)->limit($Page->firstRow. ',' . $Page->listRows)->select();
}
$this->page = $Page->show();
}else if($find == 4){
if($order != ""){
$this->list = $model->alias("t1")->join($join)->field($field)->where($map)->order($order)->limit($Page->firstRow. ',' . $Page->listRows)->find();
}else{
$this->list = $model->alias("t1")->join($join)->field($field)->where($map)->limit($Page->firstRow. ',' . $Page->listRows)->find();
}
}
$this->limit = $Page->firstRow;
$this->assign("listinfo",$this->list);
$this->assign("page",$this->page);
return($this->list);
}
}
}
if($this->txt_keyword){
$where['m_title'] = array('like','%'.$this->txt_keyword.'%');
}
$where['status'] = $param['status'] = 0;
$this->_select($this->information_mod,$where,'','*',0,10,'',$param);
$this->display();
style>
.hg_page .first, .hg_page .current, .hg_page .num, .hg_page .next, .hg_page .end, .hg_page .rows, .hg_page .prev{
float: left;
height: 37px;
padding: 0 15px;
border: 1px solid #e5e5e5;
line-height: 37px;
margin: 0 3px;
}
.hg_page{
text-align: center;
height: 37px;
margin:0 auto;
margin-top: 30px;
margin-bottom: 20px;
width: 800px;
}
/style>
更多關(guān)于thinkPHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《ThinkPHP入門教程》、《thinkPHP模板操作技巧總結(jié)》、《ThinkPHP常用方法總結(jié)》、《codeigniter入門教程》、《CI(CodeIgniter)框架進(jìn)階教程》、《Zend FrameWork框架入門教程》及《PHP模板技術(shù)總結(jié)》。