El Forum
01-26-2009, 03:45 PM
[eluser]yogal[/eluser]
Solution:
If you want to change pagination settings dynamically based on user's choice - use database. Then retrieve the settings and initialize pagination class with
I hope this helps.
Hello,
I'm building a small CMS in CI and I'm using Ci's default pagination library (CI ver. 1.7.0). I would like to store configuration settings in pagination.php file and let users change them if they want.
This is my pagination.php file
With every page there are few things that change:
- base_url
- total_rows
What i would like to do is set these config items in each controller separately and for the rest - use the default values from pagination.php
Knowing that, I am setting the pagination config with etc.
Here's part of my controller:
Now, this doesn't work. It seems to ignore the settings I provide here, total_rows are set to 0 - and therefore no pagination links are created.
It doesn't matter if $config['total_rows'] (in pagination.php) is already set to '' , 0, NULL or not specified at all - as long as it is not a number (> 0) it's assumed 0 despite setting it through controller.
I have to manually set this in config file - which works but doesn't allow me to change it dynamically:
However, the same command works with setting $config['per_page'] :
The case with base_url is diffrient. When set through $this->config->set_item:
it's interfering with $config['base_url'] in main config.php file used by CI. The workaround would be to replace pagination library and prefix base_url with something (use a diffrient index).
I can set all the settings without problems when reaching variables in pagination library directly:
But I know it's a very bad thing to do.
I've seen a few similar topics about this, some ppl claimed that changing pagination.php to Pagination.php had helped although for me, it doesn't matter - I can set all the values in config file and they are used/working, the problem is with changing the $config['total_rows'] dynamically.
Please, tell me if it's possible to change these values dynamically or what am I doing wrong.
Any help will be apriciated.
Regards,
yogal
Solution:
If you want to change pagination settings dynamically based on user's choice - use database. Then retrieve the settings and initialize pagination class with
Code:
$this->pagination->initialize($db_config);
I hope this helps.
Hello,
I'm building a small CMS in CI and I'm using Ci's default pagination library (CI ver. 1.7.0). I would like to store configuration settings in pagination.php file and let users change them if they want.
This is my pagination.php file
Code:
$config['per_page'] = '10';
$config['page_query_string'] = FALSE;
$config['full_tag_open'] = '';
$config['full_tag_close'] = '';
//First link
$config['first_link'] = '‹ Unol';
$config['first_tag_open'] = '';
$config['first_tag_close'] = ' ';
//Last link
$config['last_link'] = 'Last ›';
$config['last_tag_open'] = ' ';
$config['last_tag_close'] = '';
//Next link
$config['next_link'] = '>';
$config['next_tag_open'] = ' ';
$config['next_tag_close'] = ' ';
//Previous link
$config['prev_link'] = '<';
$config['prev_tag_open'] = ' ';
$config['prev_tag_close'] = '';
//Current page
$config['cur_tag_open'] = ' <b>';
$config['cur_tag_close'] = '</b>';
//Digit link
$config['num_tag_open'] = ' ';
$config['num_tag_close'] = '';
With every page there are few things that change:
- base_url
- total_rows
What i would like to do is set these config items in each controller separately and for the rest - use the default values from pagination.php
Quote:Setting preferences in a config file
If you prefer not to set preferences using the above method, you can instead put them into a config file. Simply create a new file called pagination.php, add the $config array in that file. Then save the file in: config/pagination.php and it will be used automatically. You will NOT need to use the $this->pagination->initialize function if you save your preferences in a config file.
Knowing that, I am setting the pagination config with
Code:
$this->config->set_item('total_rows', $smth);
Here's part of my controller:
Code:
$this->load->model('Guestbook_model', 'Guestbook_model');
$this->load->library('pagination');
$this->config->set_item('per_page', 10);
$total_rows = $this->Guestbook_model->count_entries();
$this->config->set_item('total_rows', $total_rows);
$this->load->library('pagination');
Now, this doesn't work. It seems to ignore the settings I provide here, total_rows are set to 0 - and therefore no pagination links are created.
It doesn't matter if $config['total_rows'] (in pagination.php) is already set to '' , 0, NULL or not specified at all - as long as it is not a number (> 0) it's assumed 0 despite setting it through controller.
I have to manually set this in config file - which works but doesn't allow me to change it dynamically:
Code:
$config['total_rows'] = '34';
However, the same command works with setting $config['per_page'] :
Code:
$this->config->set_item('per_page', 30);
The case with base_url is diffrient. When set through $this->config->set_item:
Code:
$this->config->set_item('base_url', base_url().'/admin/guestbook/');
I can set all the settings without problems when reaching variables in pagination library directly:
Code:
$this->pagination->base_url = base_url().'/admin/guestbook/';
I've seen a few similar topics about this, some ppl claimed that changing pagination.php to Pagination.php had helped although for me, it doesn't matter - I can set all the values in config file and they are used/working, the problem is with changing the $config['total_rows'] dynamically.
Please, tell me if it's possible to change these values dynamically or what am I doing wrong.
Any help will be apriciated.
Regards,
yogal