thinkphp full customization of page format, direct input to digital go to enter digital page

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

The paging effect is achieved as follows:

The following labels highlight the red font to find the file page.class.php in thinkphp/library/ Thinkpage.class.php and open the file, copy the function show, paste it in this file and change it to your custom function name, and here I change to show1, changing the logical output of the previous page, next page, first page and last page, remove the number link for loop, other unchanged, The changes are as follows:
  Public functionShow1 () {if(0 = =$this->totalrows)return''; /*Generate URL*/        $this->parameter[$this-&GT;P] = ' [PAGE] '; $this->url = U (Action_name,$this-parameter); /*Calculate Paging Information*/        $this->totalpages =Ceil($this->totalrows/$this->listrows);//Total Pages        if(!Empty($this->totalpages) &&$this->nowpage >$this-totalpages) {            $this->nowpage =$this-TotalPages; }        /*Calculate Paging Temp variable*/        $now _cool_page=$this->rollpage/2; $now _cool_page_ceil=Ceil($now _cool_page); $this->lastsuffix &&$this->config[' last '] =$this-TotalPages; //Previous Page        $up _row = $this->nowpage-1; $up _page = $up _row > 0? ' <a class= ' prev ' href= '. $this->url ($up _row). ' > '. The previous page. ' </a> ': ' <a class= ' prev ' href= ' javascript: (0); " > '. The previous page.        ' </a> ';        Next $down _row = $this->nowpage + 1; $down _page = ($down _row <= $this->totalpages)? ' <a class= ' next ' href= '. $this->url ($down _row). ' > '. Next page. ' </a> ': ' <a class= ' next ' href= ' javascript: (0); " > '. Next page.        ' </a> '; First page $the _first= $this->nowpage > 1? ' <a class= ' first ' href= '. $this->url (1). ' > '. Home. ' </a> ': ' <a class= ' first ' href= ' javascript: (0); " > '. Home.        ' </a> '; Last page $the _end = $this->nowpage < $this->totalpages? ' <a class= ' end ' href= '. $this->url ($this->totalpages). ' > '. Last. ' </a> ': ' <a class= ' end ' href= ' javascript: (0); " > '. Last page.        ' </a> '; //Digital Connection        $link _page= ""; //Replace paging content        $page _str=Str_replace(            Array('%header% ', '%now_page% ', '%up_page% ', '%down_page% ', '%first% ', '%link_page% ', '%end% ', '%total_row% ', '%total_page% ' '),Array($this->config[' header '],$this->nowpage,$up _page,$down _page,$the _first,$link _page,$the _end,$this->totalrows,$this->totalpages),$this->config[' Theme ']); return"{$page _str}"; }

Defining data in a query database and paging in defined model

 Public functionGetdocpagelist ($table,$where,$p,$pageSize,$order= ' DocId desc '){        $list= M ($table)->where ($where)->order ($order)                            ->page ($p.','.$pageSize)                            -Select (); $count= M ($table)->field (' * ')                        ->where ($where)                        ->order ($order)                        -Count(); $Page=New\think\page ($count,$pageSize); $module _name = '/'. Module_name. '/' . Controller_name. '/' . action_name;//here is the Get path, module name/Controller name/method name//$page is the static code display of the above effect
$Page->setconfig (' header ', ' <p><span>%now_page%</span>/<span title= '%total_page% ' Class= "All" >%TOTAL_PAGE%</span></p> <p> go to <input type= "text" id= "Page_num" class= "Txt_pa GE "/> Page </p> <a class=" gopage "href=" '. $module _name. ' /p/">GO</a>"); $Page->setconfig (' theme ', '%first%%up_page%%link_page%%down_page%%end%%header% '); $show=$Page-Show1 (); $result[' pages '] =$show; $result[' list '] =$list; $result[' count '] =$count; return $result; }

The CSS style for pagination above is as follows

/*page Out*/. D_page{width:700px;Clear:both;margin:0px Auto;Padding-top:20px;}. D_page A,.d_page P{Display:Inline-block;margin:0px 8px;}. D_page a,.d_page Input{Border:1px solid #e6e6e6;padding:5px 10px;}. D_page input{width:40px}. d_page a:hover{background:#d57a22;Border:1px solid #d57a22;Color:#fff;}

In the controller call the function under the model above, here I look at the User data table as an example:

//defining objects, referencing controllers Public function__construct () {Parent::__construct (); $this->docinfo_model =New\common\model\docinfomodel (); }$result=$this->docinfo_model->getdocpagelist (' User ',$where,$p,$pageSize,$order);$this->assign ("DocList",$result[' List ']);$this->assign ("Count",$result[' Count ']);$this->assign ("pages",$result[' Pages ']);$this->display ();

Output pages directly in the template

< Div > {$pages} </ Div >

Using jquery to implement paging jumps

<script src= ' __public__/js/jquery-1.8.3.min.js' ></script>
<script> $ (function () { //Paging Jump $ (' #page_num '). blur (function () { var url=$ ('. Gopage '). attr (' href '); var strs=url.substr (0); var Value=this.value; var all=$ ('. All '). attr ("title"); var i=parsefloat (all);//convert characters to numbers if (value<=i &&!isnan (value) && value>0) { value= Math.ceil (value); } else{ value= '; } var Nuwurl=strs+value; $ (". Gopage"). attr ("href", Nuwurl);} ); </script>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.