I just learned the php + smarty template paging class and I don't know how to call it.

Source: Internet
Author: User
Tags smarty template
Dear Big Brother, I just learned the php + smarty template paging class. I don't know how to call it! Paging class & lt ;? Php /************************************** **************************************** ** & nbsp; * br, big brother and younger brother, I just learned the php + smarty template paging class. I don't know how to call it!
Paging type
/*************************************** **************************************** *
* Brophp.com pagination class. you can customize the pagination content. *
**************************************** ****************************************
* License statement: a "learning" ultra-lightweight PHP framework designed for php readers and LAMP brothers. *
**************************************** ****************************************
* All rights reserved (C) 2011-2013 Beijing Yi diyou Education Consulting Ltd. *
* Website address: http://www.lampbrother.net (LAMP brother )*
**************************************** ****************************************
* $ Author: Gao Luofeng (skygao@lampbrother.net) $ *
* $ Date: 10:00:00 $ *
**************************************** ***************************************/
Class Page {
Private $ total; // The total number of records in the data table
Private $ listRows; // number of lines displayed per page
Private $ limit; // SQL statement using limit from name
Private $ uri; // url
Private $ pageNum; // Number of pages
// Display the content in the page information, which can be set by yourself
Private $ config = array ('head' => "record", "prev" => "previous page", "next" => "next page ", "first" => "homepage", "last" => "last ");
Private $ listNum = 10; // The number of display pages by default.

/**
* Constructor: you can set the attributes of the paging class.
* @ Param int $ total calculate the total number of records on the page
* @ Param int $ listRows (optional) number of records to be displayed on each page by default.
* @ Param string $ pa: Optional. it is used 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;
}


$ This-> pageNum = ceil ($ this-> total/$ this-> listRows );
$ This-> limit = $ this-> setLimit ();
}

/**
* This parameter is used to set the display page information for consistent operations.
* @ Param string $ param is the subscript of array config
* @ Param string $ value is used to set the element value corresponding to the config subscript.
* @ Return object returns the current object $ 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;
}

}


Private function pageList (){
$ LinkPage =" ";

$ Inum = floor ($ this-> listNum/2 );

For ($ I = $ inum; $ I >=1; $ I --){
$ Page = $ this-> page-$ I;

If ($ page> = 1)
$ LinkPage. = "uri} page/{$ page} '> {$ page }";

}

If ($ this-> pageNum> 1)
$ LinkPage. = "{$ this-> page }";


For ($ I = 1; $ I <= $ inum; $ I ++ ){
$ Page = $ this-> page + $ I;

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.