Codeigniter分页 [英] Codeigniter Pagination

查看:213
本文介绍了Codeigniter分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的代码中有一点问题,我不能解决。
I m使用CI 1.7.2。
我已经将CI分页正确地实现到系统中。
结果显示正常,但分页中的链接无法正确呈现。



例如。如果我点击第2页,然后结果显示为第2页,但分页数字上的当前链接仍为1,应该更改为2。



这里是已实现的代码

  $ total = $ this-> bmodel-> countResultsBanner 

$ data ['total'] = $ total;

$ uri_segment = $ this-> uri-> segment(4);

if($ uri_segment == 0 || empty($ uri_segment)){
$ uri_segment = 0;
}

$ perPage = 5;



$ config ['base_url'] = base_url()。index.php / modules / banner / index;

$ config ['total_rows'] = $ total;

$ config ['per_page'] = $ perPage;

$ config ['num_links'] = 4;

// $ config ['cur_tag_open'] ='< b>< span class =current_page>';

// $ config ['cur_tag_close'] ='< / span>< / b>';

$ this-> pagination-> initialize($ config);

$ result = $ this-> bmodel-> getAllBanners($ perPage,$ uri_segment);


$ data ['result'] = $ result;


/ p>

解决方案

Heyy,



我也遇到过同样的问题。最后,解决方案变得非常简单。 :)



默认情况下,CI假定用于分页的uri段是(3)。在你的情况下,对你(我假设无耻)是不正确的。

  $ config ['base_url'] = base_url()。index.php / modules / banner / index; 
$ config ['total_rows'] = $ total;
$ config ['per_page'] = $ perPage;
$ config ['num_links'] = 4;

$ config ['uri_segment'] = 3; / *包含页码的uri的段* /

$ this-> pagination-> initialize($ config);

希望这解决了您的问题


There is a bit of problem in my code which i am not able to solve. I m using CI 1.7.2. I have implemented the CI Pagination into the system correctly. The results are displayed fine but the links in the pagination are not rendering correctly.

For eg. If i click on the page 2 then the results are displayed as per the 2nd Page but the current link at pagination numbers remains 1 which should change to 2.

Here is the code that has been implemented

$total = $this->bmodel->countResultsBanner();

    $data['total'] = $total;

    $uri_segment = $this->uri->segment(4);

    if($uri_segment == 0 || empty($uri_segment)){
    $uri_segment = 0;
    }

    $perPage = 5;



    $config['base_url'] = base_url()."index.php/modules/banner/index";

    $config['total_rows'] = $total;

    $config['per_page'] = $perPage;

    $config['num_links'] = 4;

    //$config['cur_tag_open'] = '<b><span class="current_page">';

    //$config['cur_tag_close'] = '</span></b>'; 

    $this->pagination->initialize($config); 

    $result = $this->bmodel->getAllBanners($perPage,$uri_segment);


    $data['result'] = $result;

thanks in advance.

J

解决方案

Heyy,

I also faced the same problem. In the end, solution turned out to be very simple. :)

by default CI assumes that uri segment used for pagination is (3). Which in your case, for you (i am assuming shamelessly) is incorrect.

$config['base_url'] = base_url()."index.php/modules/banner/index";
$config['total_rows'] = $total;
$config['per_page'] = $perPage;
$config['num_links'] = 4;

$config['uri_segment'] = 3; /* segment of your uri which contains the page number */

$this->pagination->initialize($config);

Hope this solves your problem

这篇关于Codeigniter分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆