Codeigniter Pagination bug

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-25 17:06:38

问题


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

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?


回答1:


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");

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.

So controller should be

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?



来源:https://stackoverflow.com/questions/4408766/codeigniter-pagination-bug

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!