PHP & 技术 09 Apr 2007 03:44 pm

用pear::pager产生html翻页

网站需要使用全静态页面进行翻页。
只需修改pager类的fileName和append两个option就可以实现
将list.php?page=2改为list_2.html

  1. fileName [string]
  2.  
  3. name of the page, with a "%d" if append == TRUE.
  4.  
  5. fixFileName [boolean]
  6.  
  7. If set to FALSE, the fileName option is not overridden. Use at your own risk.
  8.  
  9. append [boolean]
  10.  
  11. If TRUE pageID is appended as GET value to the URL. If FALSE it is embedded in the URL according to fileName specs.

pear::pager文档
http://pear.php.net/manual/en/package.html.pager.factory.php

以下为函数

  1. /**
  2. * 获得html分页对象
  3. *
  4. * @param    int     $limit      每页显示数目
  5. * @param    int     $cnt        总数
  6. * @param    int     $filename   文件名格式
  7. * @return   object
  8. */
  9. function get_html_pager($limit, $cnt,$filename='list_%d.html') {
  10.     include_once('Pager/Pager.php');
  11.     $options = array(
  12.         'perPage'       => $limit,
  13.         'delta'         => 10,
  14.         'url'           => '',
  15.         'clearIfVoid'   => true,
  16.         'urlVar'        => 'Page',
  17.         'mode'          => 'Jumping',
  18.         'totalItems'    => $cnt,
  19.         'prevImg'       => '上一页',
  20.         'nextImg'       => '下一页',
  21.         'firstPageText' => '首页',
  22.         'lastPageText'  => '末页',
  23.         'linkClass'     => '',
  24.         'curPageLinkClassName'  => 'strong',
  25.         'excludeVars'   => array('Flush'),
  26.         'path'          => './',
  27.         'fileName'      => $filename,
  28.         'append'        => false,
  29.         //'spacesAfterSeparator'                => 1,
  30.     );
  31.     $pager = Pager::factory($options);
  32.     return $pager;
  33. }

Trackback This Post | Subscribe to the comments through RSS Feed

Leave a Reply