Pear的Pager分页类

Pear的 Pager分页类是一个很好用的 php分页类,扩展性很强,能够适应各种分页情况的需求,至少我在几年间大大小小的项目里,基本上没有为分页额外写过代码,全部都是用的Pager,足见Pager的可用性之强.下面用代码来看看它的使用范例:

PHP:
  1. <?php
  2. require_once 'Pager/Pager.php';
  3. $params = array (
  4.     'mode'       => 'Jumping',
  5.     'perPage'    => 3,
  6.     'delta'      => 2,
  7.     'itemData'   => array ( 'a', 'b', 'c', 'd', 'e', [...omissis... ], 'z' )
  8. );
  9. $pager = & Pager:: factory ( $params );
  10. $data  = $pager-> getPageData ( );
  11. $links = $pager-> getLinks ( );
  12. //$links is an ordered+associative array with 'back'/'pages'/'next'/'first'/'last'/'all' links
  13. //NB: $links['all'] is the same as $pager->links;
  14.  
  15. //echo links to other pages:
  16. echo $links [ 'all' ];
  17.  
  18. //Pager can also generate <link rel="first|prev|next|last"> tags
  19. echo $pager-> linkTags;
  20.  
  21. //Show data for current page:
  22. echo 'PAGED DATA: ' ; print_r ( $data );
  23.  
  24. //Results from methods:
  25. echo 'getCurrentPageID()...: '; var_dump ( $pager-> getCurrentPageID ( ) );
  26. echo 'getNextPageID()......: '; var_dump ( $pager-> getNextPageID ( ) );
  27. echo 'getPreviousPageID()..: '; var_dump ( $pager-> getPreviousPageID ( ) );
  28. echo 'numItems()...........: '; var_dump ( $pager-> numItems ( ) );
  29. echo 'numPages()...........: '; var_dump ( $pager-> numPages ( ) );
  30. echo 'isFirstPage()........: '; var_dump ( $pager-> isFirstPage ( ) );
  31. echo 'isLastPage().........: '; var_dump ( $pager-> isLastPage ( ) );
  32. echo 'isLastPageComplete().: '; var_dump ( $pager-> isLastPageComplete ( ) );
  33. echo '$pager->range........: '; var_dump ( $pager-> range );
  34. ?>
 

你可能感兴趣的:(Pear的Pager分页类)