I just learned php+smarty template pagination class and don't know how to call
Source: Internet
Author: User
Brother, I just learned Php+smarty template page class, do not know how to call!
Pagination class
/** ******************************************************************************
* Brophp.com pagination class, you can customize the page display content. *
* *******************************************************************************
* License Statement: A "learning" ultra-lightweight PHP framework for "PHP" readers and Lamp brothers students. *
* *******************************************************************************
* Copyright (C) 2011-2013 Beijing Yi Gifted Education Consulting Limited, and all rights reserved. *
* Website address: http://www.lampbrother.net (lamp brother Company) *
* *******************************************************************************
* $Author: Gaulo ([email protected]) $ *
* $Date: 2011-07-18 10:00:00 $ *
* ******************************************************************************/
Class Page {
Private $total; Total number of records in the data table
Private $listRows; Number of rows displayed per page
Private $limit; The SQL statement uses the limit from the name
Private $uri; URL address
Private $pageNum; Pages
Display content in the paging information, you can set your own
Private $config =array (' head ' = "record", "Prev" and "prev", "Next" = "Next", "first" = "Home", "last" and "End");
Private $listNum = 10; The number of default page list displays
/**
* Construction method, you can set the properties of the paging class
* @param int $total Calculate the total number of records for pagination
* @param int $listRows Optional, default number of records to display per page
* @param string $pa Optional, to pass parameters to the target page
*/
Public function __construct ($total, $listRows =25, $pa = "") {
$this->total= $total;
$this->listrows= $listRows;
$this->uri= $this->geturi ($PA);
$page =!empty ($_get["page"])? $_get["Page"]: 1;
if ($total > 0) {
if (Preg_match ('/\d/', $page)) {
$this->page=1;
}else{
$this->page= $page;
}
}else{
$this->page=0;
}
/**
* Used to set the display of paging information, can be consistent operation
* @param string $param is the subscript of the array config
* @param string $value to set the element value corresponding to the config subscript
* @return Object returns the object itself $this
*/
function set ($param, $value) {
if (Array_key_exists ($param, $this->config)) {
$this->config[$param]= $value;
}
return $this;
}
Private Function Setlimit () {
if ($this->page > 0)
Return ($this->page-1) * $this->listrows. ", {$this->listrows}";
Else
return 0;
}
Private Function GetURI ($PA) {
if ($pa = = "")
return $GLOBALS ["url"].$_get["a"]. ' /';
Else
return $GLOBALS ["url"].$_get["a"]. ' /'. Trim ($pa, "/"). ' /';
}
Private Function __get ($args) {
if ($args = = "Limit")
return $this->limit;
Else
return null;
}
Private Function Start () {
if ($this->total==0)
return 0;
Else
Return ($this->page-1) * $this->listrows+1;
}
Private Function End () {
return min ($this->page* $this->listrows, $this->total);
}
Private Function Firstprev () {
if ($this->page > 1) {
$str = "Uri}page/1 ' >{$this->config[" First "]}";
$str. = "uri}page/". ($this->page-1). "' >{$this->config["prev"} ";
return $str;
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service