Call in the entry file
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 = "<div class = \" {$ params ['myclass']} \ "> ";
If ($ params ['pager'] ['current _ page']! = $ Params ['pager'] ['first _ page']) {
$ Url = spUrl ($ params ['C'], $ params ['a'], $ args + array ($ pagerhandle => $ params ['pager'] ['prev _ page']);
$ Html. = "<a href = \" {$ url} \ "> <Prev </a> ";
} Else {
$ Html. = "<span class = \" disabled \ "> <Prev </span> ";
}
$ Offset = $ params ['offset']? $ Params ['offset']: 200; // you can use offset = x in <{pager}>.
Foreach ($ params ['pager'] ['all _ page'] as $ page ){
If ($ page = $ params ['pager'] ['current _ page']) {
$ Html. = "<span class = \" current \ ">{$ page} </span> ";
} Else {
If ($ params ['pager'] ['current _ page'] <$ offset & $ page <$ offset) |
($ Params ['pager'] ['current _ page']> $ params ['pager'] ['last _ page']-$ offset & $ page> $ params ['pager'] ['last _ page']-$ offset) |
($ Page <$ params ['pager'] ['current _ page'] + $ offset & $ page> $ params ['pager'] ['current _ page'] -$ offset)
){
$ Url = spUrl ($ params ['C'], $ params ['a'], $ args + array ($ pagerhandle => $ page ));
$ Html. = "<a href = \" $ url \ ">{$ page} </a> ";
}
}
}
If ($ params ['pager'] ['current _ page']! = $ Params ['pager'] ['last _ page']) {
$ Url = spUrl ($ params ['C'], $ params ['a'], $ args + array ($ pagerhandle => $ params ['pager'] ['Next _ page']);
$ Html. = "<a href = \" $ url \ "> Next> </a> ";
} Else {
$ Html. = "<span class = \" disabled \ "> Next> </span> ";
}
$ Html. = '</div> ';
Return $ html;
}
Template call Method
<{Pager = $ pager myclass = "num" c = "news" a = "newslist" offset = 5}>
Use in the controller:
[Php]
// Information List
Function newslist (){
$ Newsobj = spClass ("lib_news ");
// SpPager is used here, And spArgs is used to receive the incoming page parameters.
$ This-> results = $ newsobj-> spPager ($ this-> spArgs ('page', 1), 12)-> findAll (null, 'Id desc ');
// Retrieve the paging data and send it to the smarty template.
$ This-> pager = $ newsobj-> spPager ()-> getPager ();
$ This-> display ("admin/news_list.html ");
}
CSS style
[Css]
. Num {
Clear: both; margin: 0 auto; width: 500px; padding: 15px 0 0 0;
}
. Num {
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
}