Welcome Guest, Not a member yet? Register   Sign In
Pagination config file and ontime changes
#1

[eluser]Unknown[/eluser]
Hi all

I am trying to do something, but i don't know if it's possible.

The thing is that i want to have general pagination configuration stored in the pagination.php config file (i mean, open/close tags, per pages units, number of links on each side, etc... ) but i have to keep control on some other parameters, like base_url or total_rows. Maybe i didn't understand how it works, but the thing is that i have this code:
Code:
$pagination_config = array(
             'base_url'         => site_url() . '/home/show_category_grid/'.$uri_family.'/'. $uri_category. '/',
             'total_rows'     => $this->product->get_total_products_by_category($uri_family, $uri_category),
        'uri_segment'    => 5,
             'per_page'         => 9,
             'num_links'     => 10,
             'next_link'     => 'SIGUIENTES',
             'prev_link'     => 'ANTERIORES',
             'first_link'     => '<<',
             'last_link'     => '>>',
             'next_tag_open'    => '<span id="paginator_nav" class="gold">',
             'prev_tag_open' => '<span id="paginator_nav" class="gold">',
             'first_tag_open'=> '<span id="paginator_nav" class="gold">',
             'last_tag_open' => '<span id="paginator_nav" class="gold">',
             'next_tag_close'=> '</span>',
             'prev_tag_close'=> '</span>',
             'first_tag_close'=>'</span>',
             'last_tag_close'=> '</span>',
             );
$this->pagination->initialize($pagination_config);
which is actually working, but it is repeated in so many places. I've tried to store $pagination_config array into pagination.php config file, except base_url and so on, and it's not working.

My question is: do i have to call the config array $config?

How can i store all this fields:
Code:
'per_page'     => 9,
             'num_links'     => 10,
             'next_link'     => 'SIGUIENTES',
             'prev_link'     => 'ANTERIORES',
             'first_link'     => '<<',
             'last_link'     => '>>',
             'next_tag_open'    => '<span id="paginator_nav" class="gold">',
             'prev_tag_open' => '<span id="paginator_nav" class="gold">',
             'first_tag_open'=> '<span id="paginator_nav" class="gold">',
             'last_tag_open' => '<span id="paginator_nav" class="gold">',
             'next_tag_close'=> '</span>',
             'prev_tag_close'=> '</span>',
             'first_tag_close'=>'</span>',
             'last_tag_close'=> '</span>',
in a config file and change other fields on demand? Is it possible to do so?

Thank you all in advance!!!

CODEIGNITER RULEZ!!!!!!

Kaspar
#2

[eluser]nzmike[/eluser]
I'm not sure if this is the best way and I haven't actually tested it but you should be able to do something like this:

I assume you have a config file called 'pagination_config' with your $pagination_config array.

Code:
$pagination_config = $this->config->item('pagination', 'pagination');
$pagination_config['base_url'] = 'http://foobar.com';

$this->pagination->initialize($pagination_config);
#3

[eluser]Unknown[/eluser]
I will try and let you know.

Thanks! That was fast!
#4

[eluser]Unknown[/eluser]
OK this is easy, but confusing because CI states that:
Quote:You will NOT need to use the $this->pagination->initialize function if you save your preferences in a config file.

With that I tried something similar to the above work until I realized I was paying attention to the "NOT" and not the "need". Need should have been all caps because it is the key to the puzzle.

1. Set your custom settings that you want to use site wide in a file named:
Quote:pagination.php
Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    $config['num_links'] = 3;
    $config['next_link'] = '&rsaquo;';
    $config['prev_link'] = '&lsaquo;';
    $config['first_link'] = '&laquo;';
    $config['last_link'] = '&raquo;';
    
    $config['first_tag_open'] = '<span class="large_txt">';
    $config['first_tag_close'] = '</span>';
    $config['last_tag_open'] = '<span class="large_txt">';
    $config['last_tag_close'] = '</span>';
    
    $config['next_tag_open'] = '<span class="large_txt">';
    $config['next_tag_close'] = '</span>';
    $config['prev_tag_open'] = '<span class="large_txt">';
    $config['prev_tag_close'] = '</span>';

2. In the controller do as normal:
Code:
function index(){
    $this->load->library('pagination');

    $config['base_url'] = 'http://example.com/index.php/test/page/';
    $config['total_rows'] = '200';
    $config['per_page'] = '20';

    $this->pagination->initialize($config);

That is it, when you use a custom pagination.php file AND set additional config items in your controller then still use
Code:
$this->pagination->initialize($config);
CI will apply the config items in the following order:
(this assumes you used a pagination.php file in application->config folder but still want to set a few settings per controller)
Quote:
1. base_settings for pagination.
Quote:2. Pagination.php (this will win over same name items in default config)
Quote:3. Controller level.(This will win over default and any pagination.php config files, this is also dependent on you using
Code:
$this->pagination->initialize($config);
in your controller. If you don't any config items set in the controller will be ignored)

So you see that you were simply over thinking it that is all. Have a good day.




Theme © iAndrew 2016 - Forum software by © MyBB