Skip to content


用pear::pager产生html翻页

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


fileName [string]

name of the page, with a “%d” if append == TRUE.

fixFileName [boolean]

If set to FALSE, the fileName option is not overridden. Use at your own risk.

append [boolean]

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

以下为函数

/**
* 获得html分页对象
*
* @param int $limit 每页显示数目
* @param int $cnt 总数
* @param int $filename 文件名格式
* @return object
*/
function get_html_pager($limit, $cnt,$filename=’list_%d.html’) {
include_once(‘Pager/Pager.php’);
$options = array(
‘perPage’ => $limit,
‘delta’ => 10,
‘url’ => ”,
‘clearIfVoid’ => true,
‘urlVar’ => ‘Page’,
‘mode’ => ‘Jumping’,
‘totalItems’ => $cnt,
‘prevImg’ => ‘上一页’,
‘nextImg’ => ‘下一页’,
‘firstPageText’ => ‘首页’,
‘lastPageText’ => ‘末页’,
‘linkClass’ => ”,
‘curPageLinkClassName’ => ‘strong’,
‘excludeVars’ => array(‘Flush’),
‘path’ => ‘./’,
‘fileName’ => $filename,
‘append’ => false,
//’spacesAfterSeparator’ => 1,
);
$pager = Pager::factory($options);
return $pager;
}

Posted in PHP, 技术.


No Responses (yet)

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.