本文共 2047 字,大约阅读时间需要 6 分钟。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | public function alist() { $this ->validateLogin(); $this ->createurl(); $article = M( 'article' ); $page = I( 'get.page' ); $perpage = 20; $page = (isset( $page ) && ( $page >0)) ? $page : 1; //current page $last = $page - 1; $next = $page + 1; $url = "http://" . $_SERVER [ 'SERVER_NAME' ] . $_SERVER [ 'PHP_SELF' ] . "?page=" ; $sum = count ( $article ->where( "is_delete=0" )->select()); $pages = ceil ( $sum / $perpage ); $this ->assign( 'sum' , $sum ); $this ->assign( 'pages' , $pages ); if ( $page > 1) { $arr = "<a href='" . $url . "1''>首页</a>" ; $arr .= "<a href='" . $url . $last . "''>上一页</a>" ; } else { $arr = "<a href='javascript:void(0)' class='noallow'>首页</a>" ; $arr .= "<a href='javascript:void(0)' class='noallow'>上一页</a>" ; } if ( ( $page -2)>0 ) { $arr .= "<a href='" . $url . $last . "'' class=\"number\">" . ( $page -2) . "</a>" ; $arr .= "<a href='" . $url . $last . "'' class=\"number\">" . ( $page -1) . "</a>" ; } else if ( (( $page -2)<=0) && (( $page -1)>0) ) { $arr .= "<a href='" . $url . $last . "'' class=\"number\">" . ( $page -1) . "</a>" ; } $arr .= "<a href='" . $url . $last . "'' class=\"number current\">" . ( $page ) . "</a>" ; if ( ( $page +1)<= $pages ) { $arr .= "<a href='" . $url . $next . "'' class=\"number\">" . ( $page +1) . "</a>" ; if ( ( $page +2)<= $pages ) { $arr .= "<a href='" . $url . $next . "'' class=\"number\">" . ( $page +2) . "</a>" ; } } if ( $page < $pages ) { $arr .= "<a href='" . $url . $next . "''>下一页</a>" ; $arr .= "<a href='" . $url . $pages . "''>尾页</a>" ; } else { $arr .= "<a href='javascript:void(0)' class='noallow'>下一页</a>" ; $arr .= "<a href='javascript:void(0)' class='noallow'>尾页</a>" ; } $this ->assign( 'page' , $arr ); $data = $article ->where( "is_delete=0" )->page( $page , $perpage )->select(); $this ->assign( 'article' , $data ); $this ->display(); } |
|
转载地址:http://ipgia.baihongyu.com/