class Zend_Pagination
{
private $_navigationItemCount = 6; //导航栏显示导航总页数
private $_pageSize = null; //每页项目数
private $_align = "right"; //导航栏显示位置
private $_itemCount = null; //总项目数
private $_pageCount = null; //总页数
private $_currentPage = null; //当前页
private $_front = null; //前端控制器
private $_PageParaName = "page"; //页面参数名称
private $_firstPageString = "|<<"; //导航栏中第一页显示的字符
private $_nextPageString = ">>"; //导航栏中前一页显示的字符
private $_previousPageString = "<<"; //导航栏中后一页显示的字符
private $_lastPageString = ">>|"; //导航栏中最后一页显示的字符
private $_splitString = " | "; //页数字间的间隔符
public function __construct($itemCount, $pageSize)
{
if (!is_numeric($itemCount) || (!is_numeric($pageSize))) {
throw new Exception("Pagination Error:not Number");
}
$this->_itemCount = $itemCount;
$this->_pageSize = $pageSize;
$this->_front = Zend_Controller_Front::getInstance();
$this->_pageCount = ceil($itemCount/$pageSize); //总页数
$page = $this->_front->getRequest()->getParam($this->_PageParaName);
if (empty($page) || (!is_numeric($page))) {
//为空或不是数字,设置当前页为1
$this->_currentPage = 1;
} else {
if ($page < 1) {
$page = 1;
}
if ($page > $this->_pageCount) {
$page = $this->_pageCount;
}
$this->_currentPage = $page;
}
}
public function getCurrentPage()
{
return $this->_currentPage;
}
public function getNavigation()
{
$navigation = '
';
//当前页处于第几栏分页
$pageCote = ceil($this->_currentPage / ($this->_navigationItemCount - 1)) - 1;
//总分页栏
$pageCoteCount = ceil($this->_pageCount / ($this->_navigationItemCount - 1));
//分页栏中起始页
$pageStart = $pageCote * ($this->_navigationItemCount -1) 1;
//分页栏中终止页
$pageEnd = $pageStart $this->_navigationItemCount - 1;
if($this->_pageCount < $pageEnd) {
$pageEnd = $this->_pageCount;
}
$navigation .= "总共: {$this->_itemCount} 条 共 {$this->_pageCount} 页
";
if($pageCote > 0) { //首页导航
$navigation .= '
$this->_firstPageString ";
}
if($this->_currentPage != 1) { //上一页导航
$navigation .= '
$this->_previousPageString ";
}else{
$navigation .= $this->_previousPageString . ' ';
}
while ($pageStart <= $pageEnd) //构造数字导航区
{
if ($pageStart == $this->_currentPage) {
$navigation .= "
$pageStart" . $this->_splitString;
} else {
$navigation .= '
$pageStart"
. $this->_splitString;
}
$pageStart ;
}
if($this->_currentPage != $this->_pageCount) { //下一页导航
$navigation .= '
$this->_nextPageString ";
}else{
$navigation .= $this->_nextPageString;
}
if ($pageCote < $pageCoteCount-1) { //未页导航
$navigation .= '
$this->_lastPageString ";
}
$navigation .= ' 到
';
$navigation .= " 页
”;
返回 $navigation;
}
公共函数 getNavigationItemCount()
{
返回 $this->_navigationItemCount;
}
公共函数 setNavigationItemCoun($navigationCount)
{
if(is_numeric($navigationCount)) {
$this->_navigationItemCount = $navigationCount;
}
}
公共函数 setFirstPageString($firstPageString)
{
$this->_firstPageString = $firstPageString;
}
公共函数 setPreviousPageString($previousPageString)
{
$this->_previousPageString = $previousPageString;
}
公共函数 setNextPageString($nextPageString)
{
$this->_nextPageString = $nextPageString;
}
公共函数 setLastPageString($lastPageString)
{
$this->_lastPageString = $lastPageString;
}
公共函数 setAlign($align)
{
$align = strtolower($align);
if ($align == "center") {
$this->_align = "center";
} elseif ($align == "右") {
$this->_align = "右";
} 其他 {
$this->_align = "左";
}
}
公共函数 setPageParamName($pageParamName)
{
$this->_PageParaName = $pageParamName;
}
公共函数 getPageParamName()
{
返回 $this->_PageParaName;
}
私有函数 createHref($targetPage = null)
{
$params = $this->_front->getRequest()->getParams();
$module = $params["module"];
$controller = $params["controller"];
$action = $params["action"];
$targetUrl = $this->_front->getBaseUrl()
。 "/$module/$controller/$action";
foreach ($params as $key => $value)
{
if($key != "控制器" && $key != "模块"
&& $key != "action" && $key != $this->_PageParaName) {
$targetUrl .= "/$key/$value";
}
}
if (isset($targetPage)) { //指定目标页
$targetUrl .= "/$this->_PageParaName/$targetPage";
} else {
$targetUrl .= "/$this->_PageParaName/";
}
return $targetUrl;
}
}
语句3:select * from blog limit ($this->_curPage - 1)* self::PERPAGENUM, self::PERPAGENUM;
语句4:select * from blog limit self::PERPAGENUM offset ($this->_curPage - 1) * self::PERPAGENUM;