![]() |
[SOLVED] Storing pagination settings and changing them dynamically - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html) +--- Thread: [SOLVED] Storing pagination settings and changing them dynamically (/thread-15102.html) |
[SOLVED] Storing pagination settings and changing them dynamically - El Forum - 01-26-2009 [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 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'; 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 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'); 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 [SOLVED] Storing pagination settings and changing them dynamically - El Forum - 01-26-2009 [eluser]Colin Williams[/eluser] The pagination class has an initialize function. I would store my config options in a DB, then load them up with this function. $this->pagination->initialize($config); [SOLVED] Storing pagination settings and changing them dynamically - El Forum - 01-26-2009 [eluser]yogal[/eluser] Hi, thank you for such a fast reply. I must admit it's a brilliant idea. Having read about the configs and all I overlooked such a simple approach. But then, what is the pagination.php config file for? Is it really making things easier ? I think i will stick with a method proposed by you - it's bound to work this way. Still, part of me cant get over the "problem". I would appreciate if someone could clear things up a bit, maybe it's a CI bug ? Thanks, yogal [SOLVED] Storing pagination settings and changing them dynamically - El Forum - 01-26-2009 [eluser]Colin Williams[/eluser] Quote:But then, what is the pagination.php config file for? Is it really making things easier ? Things have been made flexible. The pagination.php config file is good for defaults. Then, the CI team made an initialization method to act as sort of a re-constructor. You typically can't just change a library's settings through the config methods. These settings get applied when the given library class is instantiated. So, changing them thereafter has no effect. [SOLVED] Storing pagination settings and changing them dynamically - El Forum - 01-27-2009 [eluser]yogal[/eluser] Yea I guess a config file is usefull when you have lots of pages with pagination and just some default setting. You can then change them manually and everything will be updated. I will mark this topic as read. Thank again. [SOLVED] Storing pagination settings and changing them dynamically - El Forum - 07-06-2009 [eluser]J. Pavel Espinal[/eluser] A good example of using pagination.php for default settings, is when you have a funny designer who made the pagination as part of the design ![]() $config['prev_tag_open'] = '<div class="botton_pagin">'; $config['previous_link'] = '<img src="'. base_url() .'images/arrow_left.png" alt="Anterior" width="36" height="36" border="0" />'; $config['prev_tag_open'] = '</div>'; Under these circumstances, you would not want to do that manually over and over and over again (Note: that's just a little bit of how the entire 'default' should look like in my case). If 'pagination.php' wouldn't exist, even Freddy Krueger would not be able to plan a worst nightmare ![]() |