Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
191 views
in Technique[技术] by (71.8m points)

Codeigniter Pagination bug

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...