好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

ThinkPHP分页实例 - Thinkphp

ThinkPHP分页实例

很多人初学thinkphp时,不太熟悉thinkphp的分页使用方法,现在将自己整理的分页方法分享下,有需要的朋友可以看看.

控制器中的代码:

$db  = M( "cost" );  $where  =  "查询条件" ;  $count  =  $db ->where( $where )-> count ();  $pagecount  = 20;  $page  =  new  \Think\Page( $count  ,  $pagecount );  $page ->parameter =  $row ;  //此处的row是数组,为了传递查询条件   $page ->setConfig( 'first' , '首页' );  $page ->setConfig( 'prev' , '上一页' );  $page ->setConfig( 'next' , '下一页' );  $page ->setConfig( 'last' , '尾页' );  $page ->setConfig( 'theme' , '%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% 第 ' .I( 'p' ,1). ' 页/共 %TOTAL_PAGE% 页 ( ' . $pagecount . ' 条/页 共 %TOTAL_ROW% 条)' );  $show  =  $page ->show();  //开源软件:phpfensi.com   $list  =  $db ->where( $where )->order( 'id desc' )->limit( $page ->firstRow. ',' . $page ->listRows)->select();  $this ->assign( 'list' , $list );  $this ->assign( 'page' , $show );  $this ->display(); 

模版中调用代码:

<div class="pagelist">{$page}</div>

附带分页样式:

.pagelist{  text-align : center ;  background : #f1f1f1 ;  padding : 7px   0 ;}  .pagelist a{  margin : 0 5px ;  border : #6185a2   solid   1px ;  display :inline- block ;  padding : 2px   6px   1px ;  line-height : 16px ;  background : #fff ;  color : #6185a2 ;}  .pagelist span{  margin : 0 5px ;  border : #6185a2   solid   1px ;  display :inline- block ;  padding : 2px   6px   1px ;  line-height : 16px ;  color : #6185a2 ;  color : #fff ;  background : #6185a2 ;} 

显示效果如下:

查看更多关于ThinkPHP分页实例 - Thinkphp的详细内容...

  阅读:76次