Page.class.php thinkphp function of class

1 . Constructor requires passing $ totalRows (total number of records) and $ ListRow (number of records per page)

    / ** 
     * function architecture 
     * @param array $ of the total number of records totalRows 
     * @param array $ ListRows number of records per page 
     * @param array $ parameter parameter tab jump 
     * / 
    public function the __construct (totalRows $, $ = ListRows 20 is, $ parameter = Array ()) { 
        C ( 'VAR_PAGE') && $ this-> P = C ( 'VAR_PAGE'); // set page parameter name 
        / * basis set * / 
        $ this-> = $ totalRows totalRows ; // set the total number of records 
        $ this-> listRows = $ listRows; // set the number of lines per page 
        $ this-> the Parameter = empty (the Parameter $) $ _GET: $ the Parameter;? 
        $ this-> nowPage empty = ( _GET $ [$ this-> the p-]) 1: intval ($ _ GET [$ this-> the p-]);? 
        $ this-> nowPage = $ this-> nowPage> 0 $ this-> nowPage: 1;? 
        $ this-> firstRow = $ this-> ListRows * ($ this-> nowPage -. 1); 
    }

2. create objects usually change their properties according to the needs

    public $ firstRow; // start line several 
    public $ listRows; // number of lines per page list public $ parameter; parameter // page jump to bring the 
    public $ totalRows; // total number of rows   public $ totalPages; // the total number of pages paged 
    public $ rollPage = 11; // page column displays the number of pages per 
    public $ lastSuffix = true; // if the last page shows the total number of pages
    
  
  //例如  
//$page->lastSuffix=false;
//$page->rollPage=4;

3 to set some specific display, such as by setConfig ()

    // 分页显示定制
    private $config  = array(
        'header' => '<span class="rows">共 %TOTAL_ROW% 条记录</span>',
        'prev'   => '<<',
        'next'   => '>>',
        'first'  => '1...',
        'last'   => '...%TOTAL_PAGE%',
        'theme'  => '%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%',
    );
        // style as you can set ------------------------------------------- --------- 
$ Page -> setConfig ( 'PREV', 'Previous' ); $ Page -> setConfig (' Next ',' next ' ); $ Page -> setConfig (' last ',' Last ' ); $ page -> setConfig (' First ',' Home ');
 
 

 

 

4 Use query parameters to limit paging parameters Page class  

  $list=$model->order('id asc')
->field('sp_user.*,sp_dept.name as deptname')
->join('sp_dept on sp_user.dept_id=sp_dept.id','LEFT')
->limit($page->firstRow.','.$page->listRows)->select();

  

The complete code is as follows

        countRows $ = $ Model -> COUNT (); // query the total number of records 
        $ Page        = new new \ of Think \ Page ( $ countRows , 3 );
         $ Page -> setConfig ( 'prev', 'Previous' );
         page $ -> setConfig ( 'the Next', 'Next' );
         $ page -> setConfig ( 'Last', 'Last' );
         $ page -> setConfig ( 'First', 'Home' );
         $ page -> = lastSuffix to false ;
         $ Page -> = rollPage. 4 ;
         $ Show        = $ Page ->show();// 分页显示输出
        $list=$model->order('id asc')->field('sp_user.*,sp_dept.name as deptname')
->join('sp_dept on sp_user.dept_id=sp_dept.id','LEFT')->limit($page->firstRow.','.$page->listRows)->select(); $this->assign('list',$list); $this->assign('show',$show); $this->display();

 

Guess you like

Origin www.cnblogs.com/mofei12138/p/11571343.html