Zend Framework Paging class usage in detail, zendframework_php tutorial

Source: Internet
Author: User
Tags zend framework

Zend Framework Paging class usage in detail, zendframework


This example describes the Zend framework paging class usage. Share to everyone for your reference, as follows:

1, pagination class pagination.php, it is best to put this class in the Zend directory

Class xy_pagination{Private $_navigationitemcount = 10;//navigation bar displays the total number of navigation pages private $_pagesize = null;//items per page private $_alig n = "right"; Navigation bar display location private $_itemcount = null; Total number of items private $_pagecount = null; Total pages Private $_currentpage = null; Current page Private $_front = null; Front Controller Private $_pageparaname = "page"; Page parameter name private $_firstpagestring = "|<<"; The characters shown on the first page of the navigation bar private $_nextpagestring = ">>"; The characters that appear on the previous page in the navigation bar private $_previouspagestring = "<<"; The next page in the navigation bar shows the characters private $_lastpagestring = ">>|";         The last page in the navigation bar shows the characters private $_splitstring = "|"; Spacing between page numbers/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); Total pages $page = $this->_front->getrequest ()->getparam ($this->_pageparaname); if (Empty ($page) | | (!is_numeric ($page)))    is empty or not a number, set the current page to 1 {$this->_currentpage = 1;      } else {if ($page < 1) $page = 1;      if ($page > $this->_pagecount) $page = $this->_pagecount;    $this->_currentpage = $page;  }}/** * Returns the current page * @param int Current page */Public Function getcurrentpage () {return $this->_currentpage;  }/** * Return to navigation column * @return string navigation html class= "pagenavigation" */Public Function getnavigation () {$navigation    = ''; $pageCote = ceil ($this->_currentpage/($this->_navigationitemcount-1))-1; The current page is in the first column of the page $pageCoteCount = ceil ($this->_pagecount/($this->_navigationitemcount-1)); Total page Bar $pageStart = $pageCote * ($this->_navigationitemcount-1) + 1; Start Page in page bar $pageEnd = $pageStart + $this->_navigationitemcount-1; End page in page bar if ($this->_pagecount < $pageEnd) {$pageEnd = $this->_pAgecount;    } $navigation. = "Total: {$this->_itemcount} bar {$this->_pagecount} page \ n";    if ($pageCote > 0)//home navigation {$navigation. = ' $this->_firstpagestring ';    if ($this->_currentpage! = 1)//previous navigation {$navigation. = ' $this->_previouspagestring '; } while ($pageStart <= $pageEnd)//constructs the digital navigation area {if ($pageStart = = $this->_currentpage) {$navigat      Ion. = "$pageStart". $this->_splitstring;      } else {$navigation. = ' $pageStart '. $this->_splitstring;    } $pageStart + +;    if ($this->_currentpage! = $this->_pagecount)//Next navigation {$navigation. = ' $this->_nextpagestring ';    if ($pageCote < $pageCoteCount-1)//no page navigation {$navigation. = ' $this->_lastpagestring ';    }//Add direct navigation box//$navigation. = ';    August 27, 2008 added error after entering incorrect page number--begin $navigation. = ";    August 27, 2008 added error--end after entering the incorrect page number $navigation. = "";  return $navigation; }/** * Get navigation bar display navigationTotal pages * * @return int navigation bar display total number of navigation pages */Public Function Getnavigationitemcount () {return $this->_navigationitemco  Unt /** * Set the navigation bar to display the total number of navigation pages * * @param int $navigationCount: The navigation bar displays the total number of navigation pages */Public function Setnavigationitemcoun ($naviga    Tioncount) {if (Is_numeric ($navigationCount)) {$this->_navigationitemcount = $navigationCount; }}/** * Set the first page display character * @param string $firstPageString first page display characters */Public function setfirstpagestring ($firstPageString  ) {$this->_firstpagestring = $firstPageString; }/** * Set previous navigation display characters * @param string $previousPageString: Previous page display characters */Public function setpreviouspagestring ($previous  pagestring) {$this->_previouspagestring = $previousPageString;  }/** * Set next page navigation display characters * @param string $nextPageString: Next page display characters */Public function setnextpagestring ($nextPageString)  {$this->_nextpagestring = $nextPageString; /** * Set the non-pager display character * @param string $nextPageString: no page display characters */public function SetlaStpagestring ($lastPageString) {$this->_lastpagestring = $lastPageString; /** * Set Navigation character display location * @param string $align: Navigation position */Public Function setalign ($align) {$align = Strtolower ($alig    n);    if ($align = = "Center") {$this->_align = "center";    }elseif ($align = = "Right") {$this->_align = ' right ';    }else {$this->_align = "Left";    }}/** * Set page parameter name * @param string $pageParamName: Page parameter name */Public Function Setpageparamname ($pageParamName) {  $this->_pageparaname = $pageParamName; /** * Get page parameter name * @return String page parameter name */Public Function Getpageparamname () {return $this->_pageparanam  E  /** * Generate navigation link address * @param int $targetPage: Navigation page * @return String link Destination address */Private function 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! = "Controller" && $key! = "module" && $key! = "A      Ction "&& $key! = $this->_pageparaname) {$targetUrl. ="/$key/$value ";    }} if (Isset ($targetPage))//Specify target page $targetUrl. = "/$this->_pageparaname/$targetPage";    else $targetUrl. = "/$this->_pageparaname/";  return $TARGETURL; }}?>

2, in the indexcontroller.php in the Indexcontroller function inside call:

Require_once ' zend/pagination.php '; $Users = new Users (),//$rows = $Users->getadapter ()->fetchone ("SELECT count ( *) from the users where ' role '! = ' admin '); Recorde count$rows = $Users->fetchall ("' role '! = ' admin '")->count (); Total Query Records $rowsperpage = 5; Perpage recordes$curpage = 1;if ($this->_request->getparam (' page ')) {    $curPage = $this->_request-> GetParam (' page ');} Search data and display$this->view->users = $Users->fetchall ("' role '! = ' admin '", ' id desc ', $rowsPerPage, ($ CURPAGE-1) * $rowsPerPage)->toarray () $Pager = new Xy_pagination ($rows, $rowsPerPage); $this->view->pagebar = $Pager->getnavigation ();

3. It is easier to call paging in view.

Pagebar?>

Or in the case of smarty templates

<{$pagebar}>

More interested in Zend related content readers can view the topic: "Zend framework of the introductory tutorial", "PHP Excellent Development Framework Summary", "Yii framework Introduction and common skills Summary", "thinkphp Introductory Tutorial", "PHP object-oriented Programming introduction tutorial "," Introduction to Php+mysql Database Operation "and" PHP common database Operation Skills Summary "

It is hoped that this article will help you to design PHP based on the Zend Framework framework.

Articles you may be interested in:

    • Zend Framework Framework Tutorial Zend_db_table_rowset Usage Example Analysis
    • Zend Framework Tutorial Zend_db_table_row Usage Example Analysis
    • Zend Framework Tutorial Zend_db_table Usage
    • Zend Framework Tutorial Zend_form component implement form submission and display Error prompt method
    • Introduction to Zend Framework Development Classic Tutorial
    • Zend Framework Smarty Extension Implementation method
    • Code analysis of routing mechanism of Zend framework framework
    • Zend Framework implementation of basic functions of the message book (with demo source download)
    • The Zend framework implements the method of storing the session in Memcache
    • Zend Framework implements multi-file upload function instances
    • Zend Framework Introduction Environment configuration and the first Hello World example (with demo source download)
    • Zend Framework Tutorial to connect the database and perform additions and deletions of the method (attached to the demo source download)
    • Zend Framework Tutorial Zend_db_table Table Association Instance detailed

http://www.bkjia.com/PHPjc/1113724.html www.bkjia.com true http://www.bkjia.com/PHPjc/1113724.html techarticle Zend Framework Paging class usage in detail, zendframework This example describes the Zend framework paging class usage. Share to everyone for your reference, as follows: 1, pagination class pagination.ph ...

  • 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.