Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...