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-开发者_如何学Python>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?
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?
精彩评论