您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息

thinkphp 3.2.2 自定义分页链接及对分页改进

2024/4/20 16:13:08发布4次查看
thinkphp 3.2.2 自定义分页链接及对分页改进
在用thinkphp做项目时,习惯了采用伪静态链接地址写法。最近把thinkphp版本升级到了thinkphp 3.2.2,文章分页总是u方法生成的链接,以前习惯用的伪静态链接地址写法不管用了,一下子摸不着头脑。平时很少去看thinkphp手册,也很不是很了解thinkphp的路由重写这一块。花了很多时间找资料,但是也没有找到合适的。最后不是得回归到thinkphp 自带的page.class.php 这个类,打开一看没有什么可以自定义分页链接的配置。
修改后的page.class.php下载地址:http://www.jb100.net/html/content-28-303-1.html
下面脚本100跟大家分享如何thinkphp 3.2.2自定义分页链接,有不对的地方请多包涵

1、在$config数组里面加上'link'=>'',
    private $config  = array(
        'header' => '共 %total_row% 条记录',
        'prev'   => '上一页',
        'next'   => '下一页',
        'first'  => '1...',
        'last'   => '...%total_page%',
        'theme'  => '%header% %first% %up_page% %link_page% %down_page% %end%',
    'link'=>'',
    );2、将private function url函数修改成以下    private function url($page){
        if($this->config['link']){
            return str_replace('[page]', $page, $this->url);
        }else{
            return str_replace(urlencode('[page]'), $page, $this->url);
        }
}3、将 public function show函数中的$this->url = u(action_name, $this->parameter);修改成以下        if($this->config['link']){
            $this->url = str_replace('zz', $this->parameter['p'], $this->config['link']);
        }else{
            $this->url = u(action_name, $this->parameter);
        } 完成以上步骤,thinkphp 3.2.2自定义分页链接功能就可以实现了。
分页链接是实现了自定义,但是怎样用呢?下面给大家分享一个实例         $com=m('article as a');
    $count      = $com->where($where)->count();
    $page       = new \think\page($count,2);
    $list = $com->fiel('a.title,a.article_id,a.picurl,a.content,a.author,a.add_time,c.cat_name')
        ->where($where)->join('ja_article_cat as c on c.cat_id =a.cat_id')
        ->order('a.add_time desc')->limit($page->firstrow.','.$page->listrows)->select();
        //    echo $com->getlastsql();
$page->setconfig('header',);
        $page->setconfig('prev',上一页);
        $page->setconfig('next','下一页');
        if($keyword){
            $page->setconfig('link','circle-'.$id.-.$keyword.-p-zz.html);
        }else{
            $page->setconfig('link','circle-'.$id.-p-zz.html);
        }
$pagelink = $page->show ();  除了自定义分页链接外,还对page.class.php进行了优化,需要的朋友可以下载,修改后的page.class.php下载地址:http://www.jb100.net/html/content-28-303-1.html
ad:真正免费,域名+虚机+企业邮箱=0元
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录