His features: simple, accept parameters, and give pages; flexibility: you can decide the name of the top or Next page (for example, prev, nex t, and so on) you can determine the number of pages displayed on each page. a packaging method is provided to adapt to different webpage structures. for example, if a webpage contains ( 1
...), And so on. note: There are two static methods in the demo code that you can ignore. This is used for project development. Call: import. you can use include to replace URL: refresh. this is an address Operation class. we will not describe it for the time being. we will have a chance to release it later, you can use this page method getUrl () http://www.oschin a.net/code/snippet_182375_6242
[PHP] code
- /**
- * FILE_NAME: Pages. php FILE_PATH:/lv/view/
- * Paging class
- *
- * @ Copyright Copyright (c) 2006-2010 mailTo: levi@cgfeel.com
- * @ Author Levi
- * @ Package lv. view. Pages
- * @ Subpackage
- * @ Version 2011-10-03
- */
- Call: import ('LV. url. URL ');
- Class Pages
- {
- Public $ num = 1;
- Public $ size = 50;
- Public $ current = 1;
- Private $ _ pages = array ();
- Private $ _ title = array ();
- Public function _ construct ($ count, $ size = 50)
- {
- $ This-> num = ceil ($ count/$ size );
- $ Size> 0 & $ this-> size = (Int) $ size;
- $ Page = isset ($ _ GET ['Page'])? (Int) trim ($ _ GET ['Page']): 1;
- $ Page> 1 & $ this-> current = (Int) $ page;
- $ This-> _ title = array ('previous page', '1 .. ', $ this-> num.' .. ', 'next page ');
- }
- /**
- * Packaging page
- * @ Param String | Array $ skirt
- * @ Param Array $ entitle
- * @ Return String
- */
- Public function warp ($ skirt, $ entitle = array ())
- {
- Empty ($ this-> _ pages) & $ this-> get ();
- $ Entitle + = $ this-> _ title;
- $ Skirt = (Array) $ skirt + array ('', NULL );
- $ Data = implode ($ skirt [1]. $ skirt [0], $ this-> _ pages );
- ! Is_null ($ skirt [1]) & $ data = $ skirt [0]. $ data. $ skirt [1];
- Return vsprintf ($ data, $ entitle );
- }
- /**
- * Retrieve pages
- * @ Param Int $ num: displays the number of pages.
- * @ Param Int $ span paging interval
- */
- Public function get ($ num = '5', $ span = '2 ')
- {
- $ This-> _ pages = array ();
- $ Start = $ this-> current-$ num + $ span;
- $ Start <1 & $ start = 1;
- $ End = $ start + $ num;
- $ End> $ this-> num & $ end = (Int) $ this-> num;
- $ This-> current> 1 & $ this-> _ pages [] = $ this-> _ setPage ($ this-> current-1, '% 1 $ s ');
- $ Start> 1 & $ this-> _ pages [] = $ this-> _ setPage (NULL, '% 2 $ s ');
- For ($ I = $ start; $ I <= $ end; $ I ++) $ this-> _ pages [] = $ this-> _ setPage ($ I, $ I );
- $ End <$ this-> num & $ this-> _ pages [] = $ this-> _ setPage ($ this-> num, '% 3 $ s ');
- $ This-> current <$ this-> num & $ this-> _ pages [] = $ this-> _ setPage ($ this-> current + 1, '% 4 $ s ');
- Return (Array) $ this-> _ pages;
- }
- Private function _ setPage ($ page, $ name = '% s ')
- {
- $ Hover = $ page ==$ this-> current? 'Class = "pageHover "':'';
- Return sprintf ('% s', URL: refresh (array ('page' => $ page), $ hover, $ name );
- }
- }
- ?>
Demonstration
- $ Pages = new Pages (100, 20 );
- $ Pages-> warp ('| ');
|