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;}
相关文章推荐
- ThinkPHP - 常用的配置项
- ThinkPHP - 加载第三方类库
- WindowManager.LayoutParams.type属性
- thinkPHP2.1自定义标签库的导入方法详解
- php取得当前时间函数
- FTP命令详解
- php自定义函数实现二维数组排序功能
- 发送邮件(php操作email)
- 使用php向mysql中插入当前时间
- php两个数字进行比较大小
- php % (末)
- 二维数组的创建与遍历(php)
- Ajax提交表单时验证码自动验证 php后端验证码检测
- php使用get_class_methods()函数获取分类的方法
- ContentProvider基本使用
- PHP+Ajax验证码验证用户登录
- php样例
- 用libmp4v2录制h264和aac rtp流为mp4文件
- PHP+Ajax实现验证码的实时验证
- sublime,phpstorm,photoshop开发工具介绍