您的位置:首页 > 编程语言 > PHP开发

thinkphp中分页类改写,实现类似ajax效果;

2016-07-20 16:09 357 查看
page.class.php中把show方法改写,文中新增的#comment 为改动地方,其他地方没有变动,
设置comment为锚;Acton中注意调用的show()方法,改变为调用show1()方法;
html中设置name为comment的标签作为锚;
<pre name="code" class="html">		<a name="comment"></a><!--抛锚,用来分页跳转类似ajax效果;-->
<div class="comments">
<h3>评论列表</h3>
<ul>
<volist name="commentdata" id="commentitem">
<li>
<div class="commentitem">
<h4>用户:{$commentitem[username]}</h4>
<div class="commentcontent">
{$commentitem[content]}
</div>
</div>
</li>
</volist>
</ul>
<div id="page" style="margin-top:10px;">{$pageshow}</div>
<div class="clear"></div>

</div>
public function show1() {if(0 == $this->totalRows) return '';$p              =   $this->varPage;$nowCoolPage    =   ceil($this->nowPage/$this->rollPage);// 分析分页参数if($this->url){$depr       =   C('URL_PATHINFO_DEPR');$url        =   rtrim(U('/'.$this->url,'',false),$depr).$depr.'__PAGE__';}else{if($this->parameter && is_string($this->parameter)) {parse_str($this->parameter,$parameter);}elseif(is_array($this->parameter)){$parameter      =   $this->parameter;}elseif(empty($this->parameter)){unset($_GET[C('VAR_URL_PARAMS')]);$var =  !empty($_POST)?$_POST:$_GET;if(empty($var)) {$parameter  =   array();}else{$parameter  =   $var;}}$parameter[$p]  =   '__PAGE__';$url            =   U('',$parameter);}//上下翻页字符串$upRow          =   $this->nowPage-1;$downRow        =   $this->nowPage+1;if ($upRow>0){$upPage     =   "<a href='".str_replace('__PAGE__',$upRow,$url)."#comment'>".$this->config['prev']."</a>";}else{$upPage     =   '';}if ($downRow <= $this->totalPages){$downPage   =   "<a href='".str_replace('__PAGE__',$downRow,$url)."#comment'>".$this->config['next']."</a>";}else{$downPage   =   '';}// << < > >>if($nowCoolPage == 1){$theFirst   =   '';$prePage    =   '';}else{$preRow     =   $this->nowPage-$this->rollPage;$prePage    =   "<a href='".str_replace('__PAGE__',$preRow,$url)."#comment' >上".$this->rollPage."页</a>";$theFirst   =   "<a href='".str_replace('__PAGE__',1,$url)."#comment' >".$this->config['first']."</a>";}if($nowCoolPage == $this->coolPages){$nextPage   =   '';$theEnd     =   '';}else{$nextRow    =   $this->nowPage+$this->rollPage;$theEndRow  =   $this->totalPages;$nextPage   =   "<a href='".str_replace('__PAGE__',$nextRow,$url)."#comment' >下".$this->rollPage."页</a>";$theEnd     =   "<a href='".str_replace('__PAGE__',$theEndRow,$url)."#comment' >".$this->config['last']."</a>";}// 1 2 3 4 5$linkPage = "";for($i=1;$i<=$this->rollPage;$i++){$page       =   ($nowCoolPage-1)*$this->rollPage+$i;if($page!=$this->nowPage){if($page<=$this->totalPages){$linkPage .= "<a href='".str_replace('__PAGE__',$page,$url)."#comment'>".$page."</a>";}else{break;}}else{if($this->totalPages != 1){$linkPage .= "<span class='current'>".$page."</span>";}}}$pageStr     =   str_replace(array('%header%','%nowPage%','%totalRow%','%totalPage%','%upPage%','%downPage%','%first%','%prePage%','%linkPage%','%nextPage%','%end%'),array($this->config['header'],$this->nowPage,$this->totalRows,$this->totalPages,$upPage,$downPage,$theFirst,$prePage,$linkPage,$nextPage,$theEnd),$this->config['theme']);return $pageStr;}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: