Codeigniter分页错误 [英] Codeigniter Pagination bug

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

问题描述

我认为在codeigniter分页库中有一个错误。由于某种原因,当我生成分页链接时,它会生成链接:

I think that there is a bug in the codeigniter pagination library. For some reason when I generate the pagination links, it generates the links as:

1 2 3 4

其中 3 链接到 / code>。

Where page 3 is linking to 4.

这里是配置变量代码,以防任何人好奇:

Here is the config variables code in case anyone is curious:

$config['base_url'] = base_url() . "index.php/test/$query_string";
$config['total_rows'] = $search_results->num_rows();
$config['per_page'] = $items_per_page;

这里是我的查询字符串示例:

And here is a sample of my query string:

?q=sample_query_string&per_page=1

有没有办法解决这个问题?

Is there a way to fix this?

推荐答案

我不会打扰查询字符串, url / controller。另外,我认为你的基本URL是错误的。它应该是(假设你在默认索引函数页上)

I wouldn't bother with the query string, use a variable passed straight from the url/controller. Also, I think your base url is wrong. It should be (assuming your are on the default index function page)

$config['base_url'] = site_url("test/index");

您不需要将vars放在基本url的末尾。如果你有查询字符串启用(我不认为你做),这是相同的,CI应该处理所有的重命名,只是提取的变量将是不同的。

You don't need to put the vars at the end of the base url. If you have query strings enabled (i don't think you do though), this would be the same, CI should handle all the renaming, just extracting the variables will be different.

所以控制器应该是

class Test extends Controller {

  function index($offset = 0)
  {

    $this->load->library('pagination');

    $config['base_url'] = site_url("test/index");
    $config['total_rows'] = $search_results->num_rows();
    $config['per_page'] = 20;
    $config['uri_segment'] = 3;

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


    // DO OTHER STUFF

  }

}

您可以在配置中设置限制。您需要从网址执行此操作吗?

You can set the limit in your config. Do you need to do it from the URL?

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

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