Welcome Guest, Not a member yet? Register   Sign In
Strange Behaviour with Pagination Class
#1

[eluser]CARP[/eluser]
Hi
I've configured the pagination class inside a controller, and was working fine.
I've put all the pagination config variables in config/pagination.php, working fine.

The problem cames now with some code I added for getting the corresponding results from the model, using per_page and offset stuff

Code from controller:

Code:
if ( $this->dx_auth->is_logged_in()) {

            $data = array();
            $this->load->model('clients_abm');
            $this->load->library('pagination');
            
            //Inicializa la paginacion
            $config['total_rows'] = 200;//$this->clients_abm->qtty();
            $config['base_url'] = site_url().'/clients/list/';
            $config['per_page'] = '20';
            $config['uri_segment'] = 3;
            $this->pagination->initialize($config);
            
            $data['hello'] = $config['per_page'];
            $data['pagination_links'] = $this->pagination->create_links();        
            $data['results'] = array();
            $data['results'] = $this->clients_abm->obtener_clientes($config['per_page'], $config['uri_segment']);
            $this->load->view('clients_list', $data);
        }
        else {
            redirect('/auth', 'location', 301);
        }

Before I got the error (after I added the call to the model, etc.), I had the following lines stored in the config/pagination.php

Code:
$config['per_page'] = '20';
$config['uri_segment'] = 3;

Now I had to move those lines into the controller itself so I don't get error...
Can any1 tell me why?

I'd like to have these variables stored globally for all the controllers, inside the config/pagination.php

Hope you've understood my problem
Thanks a lot in advance,
#2

[eluser]ecigraeme[/eluser]
You could try this

Quote:$this->config->load('pagination');
$data['results'] = $this->clients_abm->obtener_clientes($this->config->item('per_page'), $this->config->item('uri_segment'));
#3

[eluser]jcavard[/eluser]
as ecigraeme stated, if your configuration settings reside in an external file, you can access it this way:
Code:
$this->config->item('param_name');
make sure you have this file loaded as well (autoloaded or loaded manually)
Code:
$this->config->load('filename');

doc: http://ellislab.com/codeigniter/user-gui...onfig.html
#4

[eluser]jedd[/eluser]
[quote author="CARP" date="1249356853"]
I'd like to have these variables stored globally for all the controllers, inside the config/pagination.php[/quote]

You're right - this should work.

Have you tried not using the initialise function, as the pagination manual page suggests you don't need it if you have the bits in the config/pagination.php file. I mean, for testing purposes only, as obviously you want to be able to have basic config stuff set in the config file, and then modify it with new bits in an initialise function whenever you want to. (I'd expect it'd simply do an array_merge() thing on the two config arrays.)

Can you try that, though, out of curiosity? I've not used the pagination class before, so can't offer much beyond that suggestion. Oh, you could try making a syntax error in the config/pagination.php file - just in case.
#5

[eluser]CARP[/eluser]
Hi guys
Thanks for the replies
Some things:

1- If i put a syntax error in config/pagination.php CI stops, so seems to work.

2- If i erase the line
Code:
$this->pagination->initialize($config);
then i don't see pagination

3- I made it work using
Code:
$this->config->load('pagination');
$data['pagination_links'] = $this->pagination->create_links();        
$data['results'] = $this->clients_abm->get_clients($this->config->item('per_page'), $xx);
where $xx is a parameter of the controller's function
so If I call ...app/index.php/clients/list/20
then 20 value is assigned to $xx
All this because...

4- config['uri_segment'] isn't working or is not applied correctly. Tried assigning 3, 4, etc. values but none works

Thanks again




Theme © iAndrew 2016 - Forum software by © MyBB