Create a new AjaxPage.class.php in the lib\org\util\ directory of the thinkphp directory, and write the contents:
<?php//+----------------------------------------------------------------------//| thinkphp [WE CAN do it JUST it]//+----------------------------------------------------------------------//|
Copyright (c) 2009 http://thinkphp.cn All rights reserved. // +----------------------------------------------------------------------
// | Licensed (http://www.apache.org/licenses/LICENSE-2.0)//+------------------------------------------------------- ---------------
// | author:liu21st <liu21st@gmail.com>//+-------------------------------------------------------------------- --//$Id: Page.class.php 2712 2012-02-06 10:12:49z liu21st $ class Ajaxpage {//Page bar page showing the number of public $rollPage = 5;//pages jump
The parameters to be taken with the public $parameter;
The default list shows the number of rows per page public $listRows = 20;
Number of starting rows public $firstRow;
Pagination Total page number protected $totalPages;
Protected $totalRows of total number of rows;
The current number of pages protected $nowPage;
The total number of pages in the protected column is $coolPages; Pagination Displays custom protected $config = Array (' header ' => ' record ', ' prev' => ' prev ', ' Next ' => ', ' first ' => ' page ', ' last ' => ' final page ', ' Theme ' => '%totalrow%%header%
Totalpage% page%uppage%%downpage%%first%%prepage%%linkpage%%nextpage% ');
Default paging variable name protected $varPage; Public function __construct ($totalRows, $listRows = ', $ajax _func, $parameter = ') {$this->totalrows = $totalRows;
This->ajax_func = $ajax _func;
$this->parameter = $parameter; $this->varpage = C (' Var_page ')?
C (' Var_page '): ' P '; if (!empty ($listRows)) {$this->listrows = intval ($listRows);} $this->totalpages = Ceil ($this->totalrows/$ This->listrows);
Total number of pages $this->coolpages = ceil ($this->totalpages/$this->rollpage);
$this->nowpage =!empty ($_get[$this->varpage]) intval ($_get[$this->varpage]): 1; if (!empty ($this->totalpages) && $this->nowpage> $this->totalpages) {$this->nowpage = $this-
>totalPages;
$this->firstrow = $this->listrows* ($this->nowpage-1); Public Function Setconfig ($name, $value) {
if (Isset ($this->config[$name]) {$this->config[$name] = $value;}} Public function Show () {if (0 = $this->totalrows) return '; $p = $this->varpage; $nowCoolPage = ceil ($this->now
page/$this->rollpage); $url = $_server[' Request_uri ']. (Strpos ($_server[' Request_uri '], '? ')? ': "?".
$this->parameter;
$parse = Parse_url ($url); if (Isset ($parse [' query '])) {parse_str ($parse [' query '], $params); unset ($params [$p]); $url = $parse [' path ']. '? '.
Http_build_query ($params);
//Up and down page string $upRow = $this->nowpage-1;
$downRow = $this->nowpage+1; if ($upRow >0) {$upPage = "<a id= ' big ' href= ' javascript:". $this->ajax_func. " (". $upRow.") ' > ". $this->config[' prev ']."
</a> "; }else{$upPage = "";} if ($downRow <= $this->totalpages) {$downPage = "<a id= ' big ' href= ' javascript:". $this-> Ajax_func. " (". $downRow.") ' > ". $this->config[' next ']."
</a> ";
}else{$downPage = "";}//<< < > >> if ($nowCoolPage = = 1) {$theFirst = ""; $prePage = "";} Else{$preRow = $this->nowpage-$this->rollpage; $prePage = "<a id= ' big ' href= ' javascript:". $this->ajax_func. " (". $preRow.") ' > ". $this->rollpage."
Page </a> "; $theFirst = "<a id= ' big ' href= ' javascript:". $this->ajax_func. " (1) ' > ' $this->config[' a '.
</a> ";
} if ($nowCoolPage = = $this->coolpages) {$nextPage = "";
$theEnd = ""; }else{$nextRow = $this->nowpage+ $this->rollpage; $theEndRow = $this->totalpages; $nextPage = "<a id= ' big ' hr ef= ' javascript:. $this->ajax_func. " (". $nextRow.") ' > ". $this->rollpage."
Page </a> "; $theEnd = "<a id= ' big ' href= ' javascript:". $this->ajax_func. " (". $theEndRow.") ' > ". $this->config[' last ']."
</a> ";
}//1 2 3 4 5 $linkPage = ""; For ($i =1 $i <= $this->rollpage; $i + +) {$page = ($nowCoolPage-1) * $this->rollpage+ $i; if ($page!= $this-> Nowpage {if ($page <= $this->totalpages) {$linkPage. = " <a id= ' big ' href= ' javascript:". $this->ajax_ Func. " (". $page.") ' > ". $page." &Nbsp;</a> "; }else{break;} else{if ($this->totalpages!= 1) {$linkPage. = " <span class= ' current ' >". $page. "
</span> "; }} $pageStr = Str_replace (Array ('%header% ', '%nowpage% ', '%totalrow% ', '%totalpage% ', '%uppage% ', '%downpage% ', '% first% ', '%prepage% ', '%linkpage% ', '%nextpage% ', '%end% '), Array ($this->config[' header '), $this->nowpage,$ This->totalrows, $this->totalpages, $upPage, $downPage, $theFirst, $prePage, $linkPage, $nextPage, $theEnd), $
this->config[' theme ']);
return $pageStr; }}?>
In the controller, the following content is written:
<?php
class Useraction extends action{public
function User () {
import ("ORG. Util.ajaxpage ")//Import paging class note the imported Ajaxpage class
$credit = M (' user ');
$count = $credit->count (); Count the number of records
$limitRows = 5;//Set the number of records per page
$p = new Ajaxpage ($count, $limitRows, "user");//The third argument is that you need to invoke the AJAX function name of the page change
$ Limit_value = $p->firstrow. "," . $p->listrows;
$data = $credit->order (' id desc ')->limit ($limit _value)->select (); Query data
$page = $p->show ();//Generate paging information, where AJAX connections are generated
$this->assign (' list ', $data);
$this->assign (' page ', $page);
$this->display ();
}
? >
The template file is as follows:
The above is a small set for you to introduce the use of Ajax in thinkphp to achieve no refresh paging method, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!