require(sp_path . /speedphp.php);
require(app_path . '/include/functions.php');
sprun();
functions.php
[php]
spaddviewfunction('pager', '__template_pager');
function __template_pager($params) {
if (!isset($params['pager']) || emptyempty($params['pager']))
return '';
$args = array();
foreach ($params as $k => $v)
if (!in_array($k, array('c', 'a', 'pager', 'myclass', 'mypage', 'offset')))
$args[$k] = $v;
$pagerhandle = isset($params['pager']['mypage']) ? $params['pager']['mypage'] : 'page';
$html =
;
if ($params['pager']['current_page'] != $params['pager']['first_page']) {
$url = spurl($params['c'], $params['a'], $args + array($pagerhandle => $params['pager']['prev_page']));
$html .= ;
} else {
$html .= ;
}
$offset = $params['offset'] ? $params['offset'] : 200; // 可以在内用offset=x来调整
foreach ($params['pager']['all_pages'] as $page) {
if ($page == $params['pager']['current_page']) {
$html .= {$page};
} else {
if (($params['pager']['current_page'] ($params['pager']['current_page'] > $params['pager']['last_page'] - $offset && $page > $params['pager']['last_page'] - $offset ) ||
( $page $params['pager']['current_page'] - $offset )
) {
$url = spurl($params['c'], $params['a'], $args + array($pagerhandle => $page));
$html .= {$page};
}
}
}
if ($params['pager']['current_page'] != $params['pager']['last_page']) {
$url = spurl($params['c'], $params['a'], $args + array($pagerhandle => $params['pager']['next_page']));
$html .= next >;
} else {
$html .= next >;
}
$html .= '
';
return $html;
} 模板调用方法
控制器内使用:
[php]
//资讯列表
function newslist() {
$newsobj = spclass(lib_news);
// 这里使用了sppager,同时用spargs接受到传入的page参数
$this->results = $newsobj->sppager($this->spargs('page', 1), 12)->findall(null, 'id desc');
// 这里获取分页数据并发送到smarty模板内
$this->pager = $newsobj->sppager()->getpager();
$this->display(admin/news_list.html);
}
css样式
[css]
.num {
clear:both; margin:0 auto; width:500px; padding:15px 0 0 0;
}
.num a {
border-right: #ccc 1px solid; padding-right: 5px; border-top: #ccc 1px solid; padding-left: 5px; padding-bottom: 2px; margin: 2px; border-left: #ccc 1px solid; color: #000; padding-top: 2px; border-bottom: #ccc 1px solid; text-decoration: none
}
.num a:hover {
border: #0080c0 1px solid; color: #000;
}
.num a:active {
border: #0080c0 1px solid; color: #000;
}
.num span.current {
border-right: #0080c0 1px solid; padding-right: 5px; border-top: #0080c0 1px solid; padding-left: 5px; font-weight: bold; padding-bottom: 2px; margin: 2px; border-left: #0080c0 1px solid; color: #fff; padding-top: 2px; border-bottom: #0080c0 1px solid; background-color: #0080c0
}
.num span.disabled {
border-right: #eee 1px solid; padding-right: 5px; border-top: #eee 1px solid; padding-left: 5px; padding-bottom: 2px; margin: 2px; border-left: #eee 1px solid; color: #ddd; padding-top: 2px; border-bottom: #eee 1px solid
}
http://www.bkjia.com/phpjc/477876.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/477876.htmltecharticle在入口文件调用 require(sp_path . /speedphp.php); require(app_path . /include/functions.php); sprun(); functions.php [php] spaddviewfunction(pager, __template_pager); functio...
