简体   繁体   English

CodeIgniter分页:不创建第一页的链接

[英]CodeIgniter Pagination : Does not create first page's link

my pagination problem still continue ; 我的分页问题仍然存在;

I just making pagination in simple stuff : 我只是用简单的东西做分页:

        $config['base_url'] = site_url('admin/index/page/');
        $this->load->database();
        $config['total_rows'] = $this->db->count_all('sms');
        $config['per_page'] = 20;
        $offset = $this->uri->segment(4, 0);
        $this->pagination->initialize($config)

And my view page has this command for view pagination : 我的视图页面有这个命令用于视图分页:

        <?php echo $this->pagination->create_links(); ?> 

And after more than 20 rows , pagination starts to paging the list, but html output shows like this : 在超过20行之后,分页开始分页列表,但html输出显示如下:

1 2 3 1 2 3

As in view , First Page Number 1 does not have link either jumping next page , there is no link on page number 1. Just its on strong . 在视图中,第一页编号1没有链接跳转到下一页,页面编号1上没有链接。只是它强大。

My second problem is : I have just 30 record but CI pagination creates 3rd page which is coming with empty rows ! 我的第二个问题是:我只有30个记录,但CI分页创建第3页,其中有空行!

I am not sure why some Class ( specially pagination makes so much trouble to users ? ) If i need to pay something ( maybe hidden licence? ) for get away from trouble instead of using simple pagination class without loosing so much time for searching issue on internet , I am ready for it ! 我不确定为什么有些Class(特别是分页给用户带来了太多麻烦?)如果我需要支付一些东西(可能是隐藏的许可证?)以避免麻烦而不是使用简单的分页类而不会浪费那么多时间来搜索问题互联网,我准备好了!

I was very mad because of this pagination problem and I was studying the source code of the pagination library and I saw this -- var $uri_segment = 3; 由于这个分页问题,​​我非常生气,我正在研究分页库的源代码,我看到了这个 - var $ uri_segment = 3; The default of the pagination library uses the 3rd uri segment, in your case and in my case we wanted to use the 4th uri segment. 在您的情况下,分页库的默认值使用第3个uri段,在我的情况下,我们想要使用第4个uri段。 To suit our needs change this code: 为了满足我们的需求,请更改此代码

    $config['base_url'] = site_url('admin/index/page/');
    $this->load->database();
    $config['total_rows'] = $this->db->count_all('sms');
    $config['per_page'] = 20;
    $offset = $this->uri->segment(4, 0);
    $this->pagination->initialize($config)


   TO


    $config['base_url'] = site_url('admin/index/page/');
    $this->load->database();
    $config['total_rows'] = $this->db->count_all('sms');
    $config['per_page'] = 20;
    $offset = $this->uri->segment(4, 0);

    $config['uri_segment'] = 4;      // add this line to override the default

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

Kindly post back here if this will solve your problem or if the problem still exists so I can help :) 请回复此处,如果这将解决您的问题或如果问题仍然存在所以我可以帮助:)

Nwei this is not in the pagination class documentation. Nwei这不在分页类文档中。 I hope this will be added to the docs because I'm seeing many developers having a hard time with the pagination class. 我希望这会被添加到文档中,因为我看到许多开发人员在分页课上遇到了困难。

If you are familiar with how pagination works, then you should be aware that pagination does not add a link tag to the current page. 如果您熟悉分页的工作原理,那么您应该知道分页不会向当前页面添加链接标记。 So I'm not sure what you're asking in regards to "pagination class does not create 1 page link". 因此,我不确定您对“分页类不创建1页链接”的要求。

Also, I don't see where you're offset is being used within the pagination functionality. 此外,我没有看到您在分页功能中使用偏移的位置。 It seems like you set it but you don't use it. 看起来你设置它但你不使用它。 This can cause an incorrect pagination result which I assume is why you get more pagination links than you expect. 这可能导致不正确的分页结果,我认为这是为什么你获得比预期更多的分页链接。

    $offset = $this->uri->segment(4, 0);
    $this->pagination->initialize($config);

One way to change the markup for the "current page" link is 'Customizing the "Current Page" Link' 更改“当前页面”链接标记的一种方法是“自定义”当前页面“链接”

$config['cur_tag_open'] = '<a href="#">';

The opening tag for the "current" link. “当前”链接的开始标记。

$config['cur_tag_close'] = '</a>';

The closing tag for the "current" link. “当前”链接的结束标记。

The other option is to dive into the pagination class and remove the functionality it has for not adding a link to the current page. 另一个选择是深入到分页类并删除它没有添加到当前页面的链接的功能。

Really, if you're on the current page, it doesn't add any benefit to link to the same page you're already on which I'm assuming is the reason the current page doesn't have a link. 真的,如果你在当前页面上,它没有添加任何好处链接到你已经在的同一页面,我假设是当前页面没有链接的原因。 If you went to page 2 then the 2 would be disabled. 如果你去了第2页,那么2将被禁用。 Hope that makes some sense. 希望这有点道理。

No, there no need to pay anything ...CI pagination works perfectly ..you see this library http://codeigniter.com/user_guide/libraries/pagination.html 不,没有必要支付任何费用...... CI分页工作完美..你看到这个库http://codeigniter.com/user_guide/libraries/pagination.html

make sure your $config['total_rows'] = $this->db->count_all('sms'); 确保你的$config['total_rows'] = $this->db->count_all('sms'); this code is working correct and providing the correct number of rows and also i would like to suggest use .. $config['uri_segment'] = 3; 这段代码工作正常并提供正确的行数,我也建议使用.. $config['uri_segment'] = 3; or $config['uri_segment'] = 4; depend on your uri $config['uri_segment'] = 4; depend on your uri $config['uri_segment'] = 4; depend on your uri rather than using $offset = $this->uri->segment(4, 0); $config['uri_segment'] = 4; depend on your uri而不是使用$offset = $this->uri->segment(4, 0);

Hofefully these few change will work for you.... 老实说,这些改变对你有用......

I was also having the same issue in pagination when using segment number 4. I solved it by using segment number 3. Thats also my problem because I really need to use segment number 4 But Oh well it has bug. 当使用段号4时,我在分页时也遇到了同样的问题。我使用段号3来解决它。这也是我的问题,因为我真的需要使用段号4但是好吧它有bug。 I hope this can be solved ASAP. 我希望这可以尽快解决。 Or if u really need to fix this issue now u can try to fork the source code of pagination class. 或者,如果你现在真的需要解决这个问题,你可以尝试分叉分页类的源代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM