Welcome Guest, Not a member yet? Register   Sign In
Pagination; using a combination of config file and per-controller parameters
#1

[eluser]Daniel H[/eluser]
Hi

I'd like to be able to retain a global set of pagination variables in a pagination config file, but keep the core parameters - i.e. base_url/total_rows/per_page - local to the controller in which I need to generate pagination links.

I don't seem to be able to do this, presumably because the initialize() function overrides config file parameters?

Any ideas how I can do this?

Thanks.
#2

[eluser]xwero[/eluser]
create a config file pagination_default.php. But instead of doing
Code:
$config['base_url'] = 'http://example.com/index.php/test/page/';
$config['total_rows'] = '200';
$config['per_page'] = '20';
You do
Code:
$config['pagination']['base_url'] = 'http://example.com/index.php/test/page/';
$config['pagination']['total_rows'] = '200';
$config['pagination']['per_page'] = '20';
and in you controller you do
Code:
$this->load->config('pagination_default');
$config = array_merge(config_item('pagination'),array('full_tag_open'=>'','full_tag_close'=>''));
$this->pagination->initialize($config);
That should do the trick.
#3

[eluser]Daniel H[/eluser]
Hi thanks for that but it's the other way round: I want to have the core parameters in the controller and use the config params that *should* be loaded automatically by the pagination library (according to the documentation).

So I could use the same method, but how would I merge the automatically loaded config params? Or should I load the config file manually and then merge with my three local parameters?
#4

[eluser]xwero[/eluser]
same thing, it was just an example. add the settings that are shared to the config file and use array_merge to joun the shared array with the local array.

But i think it should be possible to have a partial config file that gets extended/overwritten with local settings.
#5

[eluser]Daniel H[/eluser]
Great - many thanks.




Theme © iAndrew 2016 - Forum software by © MyBB