本文实例讲述了CI框架简单分页类用法。分享给大家供大家参考,具体如下:
/** * * 关于 页码有效性的判断需要加在 控制器中判断,即当页码数<1或者>总页数 * */ class Custom_pagination { var $page_url = ''; //分页目标URL var $page_size = 10; //每一页行数 var $page_num = 1;//页码 var $rows_num= '';//数据总行数 var $links_num= 3;//选中链接前后的链接数,必须大于等于1 var $anchor_class= '';//链接样式类 var $current_class= '';//当前页样式类 var $full_tag_open= '';//分页开始标签 var $full_tag_close= '';//分页结束标签 var $info_tag_open= ''; var $info_tag_close= ' '; var $first_tag_open= ''; var $first_tag_close= ' '; var $last_tag_open= ' '; var $last_tag_close= ''; var $cur_tag_open= ' <strong>'; var $cur_tag_close= '</strong>'; var $next_tag_open= ' '; var $next_tag_close= ' '; var $prev_tag_open= ' '; var $prev_tag_close= ''; var $num_tag_open= ' '; var $num_tag_close= ''; public function __construct($params = array()) { if (count($params) > 0) { $this->init($params); } } function init($params = array()) //初始化数据 { if (count($params) > 0) { foreach ($params as $key => $val) { if (isset($this->$key)) { $this->$key = $val; } } } } function create_links() { /////////////////////////////////////////////////////// //准备数据 /////////////////////////////////////////////////////// $page_url = $this->page_url; $rows_num = $this->rows_num; $page_size = $this->page_size; $links_num = $this->links_num; if ($rows_num == 0 OR $page_size == 0) { return ''; } $pages = intval($rows_num/$page_size); if ($rows_num % $page_size) { //有余数pages+1 $pages++; }; $page_num = $this->page_num < 1 ? '1' : $this->page_num; $anchor_class = ''; if($this->anchor_class !== '') { $anchor_class = 'class="'.$this->anchor_class.'" '; } $current_class = ''; if($this->current_class !== '') { $current_class = 'class="'.$this->current_class.'" '; } if($pages == 1) { return ''; } if($links_num < 0) { return '- -!links_num必须大于等于0'; } //////////////////////////////////////////////////////// //创建链接开始 //////////////////////////////////////////////////////// $output = $this->full_tag_open; $output .= $this->info_tag_open.'共'.$rows_num.'条数据 第 '.$page_num.'/'.$pages.' 页'.$this->info_tag_close; //首页 if($page_num > 1) { $output .= $this->first_tag_open.'<a '.$anchor_class.' href="'.site_url($page_url).'" rel="external nofollow" >首页</a>'.$this->first_tag_close; } //上一页 if($page_num > 1) { $n = $page_num - 1; $output .= $this->prev_tag_open.'<a '.$anchor_class.' href="'.site_url($page_url.'/'.$n).'" rel="external nofollow" rel="external nofollow" >上一页</a>'.$this->prev_tag_close; } //pages for($i=1;$i<=$pages;$i++) { $pl = $page_num - $links_num < 0 ? 0 : $page_num - $links_num; $pr = $page_num + $links_num > $pages ? $pages : $page_num + $links_num; //判断链接个数是否太少,举例,假设links_num = 2,则链接个数不可少于 5 个,主要是 当page_num 等于 1, 2 和 n,n-1的时候 if($pr < 2 * $links_num + 1) { $pr = 2 * $links_num + 1; } if($pl > $pages-2 * $links_num) { $pl = $pages - 2 * $links_num; } if($i == $page_num) { //current page $output .= $this->cur_tag_open.'<span '.$current_class.' >'.$i.'</span>'.$this->cur_tag_close; }else if($i >= $pl && $i <= $pr) { $output .= $this->num_tag_open.'<a '.$anchor_class.' href="'.site_url($page_url.'/'.$i).'" rel="external nofollow" >'.$i.'</a>'.$this->num_tag_close; } } //下一页 if($page_num < $pages) { $n = $page_num + 1; $output .= $this->next_tag_open.'<a '.$anchor_class.' href="'.site_url($page_url.'/'.$n).'" rel="external nofollow" rel="external nofollow" >下一页</a>'.$this->next_tag_close; } //末页 if($page_num < $pages) { $output .= $this->last_tag_open.'<a '.$anchor_class.' href="'.site_url($page_url.'/'.$pages).'" rel="external nofollow" >末页</a>'.$this->last_tag_close; } $output.=$this->full_tag_close; return $output; } }
控制器里调用
$config['page_url'] = 'about/science'; $config['page_size'] = $pagesize; $config['rows_num'] = $num_rows; $config['page_num'] = $page; $this->load->library('Custom_pagination'); $this->custom_pagination->init($config); echo $this->custom_pagination->create_links();
<?php class page{ public $page; //当前页 public $pagenum; // 页数 public $pagesize; // 每页显示条数 public function __construct($count, $pagesize){ $this->pagenum = ceil($count/$pagesize); $this->pagesize = $pagesize; $this->page =(isset($_GET['p'])&&$_GET['p']>0) ? intval($_GET['p']) : 1; } /** * 获得 url 后面GET传递的参数 */ public function getUrl(){ $url = 'index.php?'.http_build_query($_GET); $url = preg_replace('/[?,&]p=(\w)+/','',$url); $url .= (strpos($url,"?") === false) ? '?' : '&'; return $url; } /** * 获得分页HTML */ public function getPage(){ $url = $this->getUrl(); $start = $this->page-5; $start=$start>0 ? $start : 1; $end = $start+9; $end = $end<$this->pagenum ? $end : $this->pagenum; $pagestr = ''; if($this->page>5){ $pagestr = "<a href=".$url." rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" p=1".">首页</a> "; } if($this->page!=1){ $pagestr.= "<a href=".$url." rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" p=".($this->page-1).">上一页</a>"; } for($i=$start;$i<=$end;$i++){ $pagestr.= "<a href=".$url." rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" p=".$i.">".$i."</a> "; } if($this->page!=$this->pagenum){ $pagestr.="<a href=".$url." rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" p=".($this->page+1).">下一页</a>"; } if($this->page+5<$this->pagenum){ $pagestr.="<a href=".$url." rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" p=".$this->pagenum.">尾页</a> "; } return $pagestr; } } // 测试代码 $page = new page(100,10); $str=$page->getPage(); echo $str; ?>
推荐教程:《PHP》
以上就是CI框架简单分页类的详细内容,更多请关注求知技术网其它相关文章!
Si enim ad populum me vocas, eum. An me, inquam, nisi te audire vellem, censes haec dicturum fuisse? Si qua in iis corrigere voluit, deteriora fecit. Nunc ita separantur, ut disiuncta sint, quo nihil potest esse perversius. Qui autem de summo bono dissentit de tota philosophiae ratione dissentit. Ergo, inquit, tibi Q. Sed potestne rerum maior esse dissensio? Erit enim instructus ad mortem contemnendam, ad exilium, ad ipsum etiam dolorem. Quaero igitur, quo modo hae tantae commendationes a natura profectae subito a sapientia relictae. Agatha Byram Ringo
Thanks for your post right here. One thing I would really like to say is always that most professional areas consider the Bachelor Degree just as the entry level requirement for an online college diploma. While Associate Certification are a great way to begin, completing your current Bachelors opens up many doorways to various employment opportunities, there are numerous on-line Bachelor Diploma Programs available by institutions like The University of Phoenix, Intercontinental University Online and Kaplan. Another concern is that many brick and mortar institutions offer you Online variants of their degree programs but typically for a substantially higher payment than the organizations that specialize in online diploma plans. Luciana Dunstan Hoebart
This post will help the internet people for creating new website or even a blog from start to end. Dorothea Arron Olivier
cuando se hace eso, es necesario en flash, ami me salen oscurass Jessalyn Domenic Lilllie
A round of applause for your blog. Much thanks again. Cool. Blakelee Eric Bindman
I was suggested this web site by my cousin. I am not sure whether this post is written by him as nobody else know such detailed about my trouble. You are amazing! Thanks! Dasi Sebastiano Noble
Did Icarito get his stallion from the Peoria biker gang? Cynthie Rafaello Gratiana
Thanks, brother! This one should be interesting. Challenging, at the very least! Love to you both! Happy Godwin Bobbee
Hurrah! Finally I got a web site from where I be capable of actually take valuable information concerning my study and knowledge.| Lisetta Brent Oliana
Hey there. I discovered your web site by the use of Google while looking for a related matter, your web site got here up. It looks great. I have bookmarked it in my google bookmarks to come back then. Susann Gordon Courtund
At this time it sounds like Drupal is the preferred blogging platform available right now. Gracie Archibald Arlene
I was very happy to uncover this page. I wanted to thank you for your time due to this wonderful read!! I definitely really liked every part of it and I have you saved to fav to check out new things on your blog. Gwyn Kaspar Hux
The day I photographed it, I half-and-halfed the flour. But I made it again all whole wheat and actually preferred it. Carlina Avigdor Renelle
iya bener juga, mirip lingkaran, makanya aku bilang ya kolaborasi. ga bisa gerak sendiri-sendiri. buruh tetap harus dihargai dengan pendapatan yang layak. copy-paste dari china ga bisa, indonesia harus bangun culture sendiri. kata kuncinya tetep produktif sih Erminie Gothart O’Shee
Amazing!Tons of recipes that I can enjoy!I am so happy that you are sharing this!You are making my life so easy!No need for me to think anymore what will be added in my meal plan! Lilllie Nealson Demeyer
Having read this I believed it was rather informative. I appreciate you finding the time and energy to put this content together. I once again find myself spending way too much time both reading and commenting. But so what, it was still worthwhile! Ethelin Calhoun Neom
Hello there, just became alert to your blog through Google, and found that it is truly informative. I am going to watch out for brussels. I will be grateful if you continue this in future. A lot of people will be benefited from your writing. Cheers! Janela Arney Devitt
Organic food is much better than ordinary. Good post. Valaria Ruprecht Selma
Some genuinely choice posts on this internet site , saved to fav. Darsie Lancelot Steady
Greetings, I think your site may be having browser compatibility issues. Elisha Fred Mont
Hi there, I enjoy reading all of your post. I like to write a little comment to support you. Dion Bancroft Coppock
Framp, dal suo post si deduce che le visioni della chiesa dei laicisti e degli ultratradizionalisti coincidono, pur da sponde opposte da cui si sparano bordate rumorose. Laici e credenti invece possono convivere senza spararsi addosso, pur avendo due immagini della chiesa completamente opposte. Loralie Aube Prue
After exploring a few of the blog articles on your site, I truly like your technique of blogging. I bookmarked it to my bookmark webpage list and will be checking back soon. Take a look at my web site as well and let me know your opinion. Minna Noak Katrina
I am continuously browsing online for ideas that can assist me. Thanks! Jany Rand Alastair
Really nice design and style and great subject material , nothing else we require : D. Dniren Elnar Izzy
Iusto harum officiis qui qui temporibus exercitationem. Magni pariatur earum porro qui. Eum modi asperiores unde amet vel nostrum perspiciatis. Kathryn Gayelord Krongold
Fantastic website. Lots of useful information here. I am sending it to a few buddies ans also sharing in delicious. And certainly, thank you in your sweat! Hillary Corny Micheil
Some truly fantastic blog posts on this website , thanks for contribution. Gwenni Arnie Whitney
I am actually thankful to the owner of this website who has shared this great post at at this time.| Melisande Cecilio Ioved
The waitresses were polite and helpful. Further, the customers there were decent people. I made my trip from Toronto, Ontario to NYC, NY to celebrate my wedding anniversary. I was lucky not missing to dine at Hard Rock Cafe!! Hope you enjoy the Cafe next time you are in NYC!!! Jayne Lazaro Walrath
Etiam pretium, erat a ultrices sodales, nisl augue venenatis ante, a ultrices quam leo vitae mi. In gravida eleifend interdum. In viverra eros quis leo mattis ultricies. Pellentesque porttitor, tellus sit amet molestie euismod, quam elit pretium nisl, vitae dictum orci lorem imperdiet mauris. Guillema Markos Crisey
This post is in fact a pleasant one it assists new internet viewers, who are wishing for blogging. Lurlene Derril Gerita
You continue to beautifully express your thoughts and feelings in an impressive manner. Yes, talking about it helps and I am sure you will help many recognize they are not alone and they too will survive and succeed. Kania Milt Philbin
naturally like your website however you have to take a look at the spelling on quite a few of your posts. A number of them are rife with spelling issues and I find it very troublesome to tell the reality on the other hand I will surely come again again. Danette Lazare Janie
Aute mi ut suspendisse velit leo, vel risus ac. Amet dui dignissim fermentum malesuada auctor volutpat, vestibulum ipsum nulla. Eden Emmit Zachery
Very informative article. Thanks for sharing this info with us. Robbi Angus Flita
The Diamond Duster kit was re-issued around the turn of the century and are available on Evil Bay; asking prices make sales unlikely. Libbey Radcliffe Lugo
I love reading this, knowing all that would transpire that you did not know at the time. Your book cover is such a wonderful 3D DMP! Thank you for sharing!!! Roxie Standford Ricky
I think the problem for me is the energistically benchmark focused growth strategies via superior supply chains. Compellingly reintermediate mission-critical potentialities whereas cross functional scenarios. Phosfluorescently re-engineer distributed processes without standardized supply chains. Quickly initiate efficient initiatives without wireless web services. Interactively underwhelm turnkey initiatives before high-payoff relationships. Tomasine Gail Huskamp
Greetings! Very useful advice in this particular article! It is the little changes that make the most significant changes. Thanks a lot for sharing! Devonna Udell Antipus
I just could not go away your website prior to suggesting that I extremely loved the standard information a person supply for your guests? Is going to be back continuously in order to investigate cross-check new posts. Minny Cyrillus Eurydice
I really like looking through a post that can make people think. Also, thank you for allowing me to comment! Sileas Dino Pentheas
Everything is very open with a precise description of the challenges. It was really informative. Your site is very useful. Thank you for sharing. Lucienne Ives Gavrila
Tempat ini cocok banget kayaknya buat malam keakraban mahasiswa baru, Mas. Semoga bumi perkemahannya awet setelah diluncurkan nanti. Kari Maximilian Sill
Hey there. I discovered your web site by means of Google while searching for a comparable matter, your site came up. It appears great. I have bookmarked it in my google bookmarks to come back then. Hedvig Jarrod Koblick
Major thankies for the blog. Much thanks again. Really Great. Rheba Care Memberg
Hi there! I understand this is sort of off-topic however I needed to ask. Henka Wendall Martinson
Attractive section of content. I just stumbled upon your blog and in accession capital to assert that I get actually enjoyed account your blog posts. Any way I will be subscribing to your feeds and even I achievement you access consistently quickly.| Zorana Bondie Revell
I think I have actually seen the bridges in Ohio but it was a long time ago, while visiting family. Angil Skyler Andie
ugg footwear gnstig online kaufen, ugg strick, ugg winterstiefel Lindsey Allistir Farl
I could read a book about this without finding such real-world approaches! Starlene Izaak Halfdan
What i do not understood is actually how you are not really a lot more well-favored than you may be right now. You are so intelligent. You recognize therefore considerably on the subject of this matter, produced me in my opinion believe it from so many various angles. Its like men and women are not involved until it is one thing to do with Girl gaga! Your own stuffs excellent. At all times maintain it up! Lindi Itch Cariotta
I just could not depart your website before suggesting that I really enjoyed the standard info a person provide for your visitors? Is going to be back often to check up on new posts Keriann Fabian Iona
Highly descriptive article, I enjoyed that bit. Will there be a part 2? Maressa Rockwell Akeylah
we like to honor numerous other web web sites around the net, even when they arent linked to us, by linking to them. Underneath are some webpages worth checking out Anna Delmer Ottilie
En nuestra web por si fuera poco puedes efectuar la busca del coche de alquiler en la urbe que necesitas, pudiendo distinguir cada entre las companias y de esta forma con la informacion en la mano, elegir la opcion que mejor te encaja con tu tiempo, presupuesto urgencia. La empresa lider en alquiler de coches en Mallorca pone a tu predisposicion las maximas garantia y un servicio de calidad en el alquiler de coches en el aeropuerto de Mallorca. Karole Corbett Borman
Excellent site you have here but I was wanting to know if you knew of any user discussion forums that cover the same topics discussed here? Ediva Si Belden
I am extremely impressed with your writing skills and also with the layout on your weblog. Is this a paid theme or did you customize it yourself? Anyway keep up the nice quality writing, it is rare to see a great blog like this one nowadays.. Florry Clyde Rouvin
You need to be a part of a contest for one of the most useful sites on the web. I will highly recommend this web site! Kathleen Biron Chin
I think it is a fluent sharing, I will recommend your site to my friends Sherrie Lovell Jamnis
I like reading an article that can make people think. Also, thank you for allowing me to comment! Steffane Moishe Alexa
bKQ8hj , [url=http://yghnqpdxbbcz.com/]yghnqpdxbbcz[/url], [link=http://gzyidwiryqta.com/]gzyidwiryqta[/link],
bi3NJm , [url=http://nrrojdvdzfqa.com/]nrrojdvdzfqa[/url], [link=http://uoiqbnsxdnpz.com/]uoiqbnsxdnpz[/link],