Reputation: 331
I have CI pagination set up and working as expected so far. As suggested in the CI docs, a I am using a pagination config file. I chose to do this to keep the controller tidy. The issue I am experiencing is that I do not know how to access and overwrite the total_rows variable.
For example, I set the variable to 200 in the config file. In my app, the number of records will be higher. I want to dynamically modify the variable locally in the controller.
I can see the object contents (below) using "print_r($this->pagination);"
CI_Pagination Object
(
[base_url:protected] => http://moxietek.com/mx03/index.php/user/index/
[prefix:protected] =>
[suffix:protected] =>
[total_rows:protected] => 200
[num_links:protected] => 3
[per_page] => 20
[cur_page] => 0
[use_page_numbers:protected] =>
[first_link:protected] => First
[next_link:protected] => Next
[prev_link:protected] => Previous
[last_link:protected] => Last
...)
Of the Q&A on pagination, each use the config setup in the controller. I can do this and everything will work, but I ultimately want to reuse the pagination configuration for other controllers. Thanks.
Upvotes: 0
Views: 287
Reputation: 9265
It seems as though the config array item key will be overridden by any element you pass to initialize:
$this->load->library('pagination');
$config['total_rows'] = 50;
$this->pagination->initialize($config);
echo $this->pagination->create_links();
So while total_rows
overrides the one /config/pagination.php
the other variables set aren't overridden.
Upvotes: 0