Welcome Guest, Not a member yet? Register   Sign In
Pagintaion
#1

[eluser]Rubiz'[/eluser]
Hello everyone!

Well, I'm trying first time use the pagination helper, it seams to be usefull and easy, but I think I'm missing something...

I dont know how it should be the model function, I dont know wich number variables I should use, well, I'm totaly lost in how select results in model, wich variables de controller should work, well, someone could help please?

It would be fine if user guide had an complete example of it :-)

Thanx!
#2

[eluser]OES[/eluser]
Hi Rubiz.

Here is a sample of my code which will hopeully shed some light.

First the controller where I am going to paginate some results.
Code:
function index()
{                    
    $offset = $this->uri->segment(3);
    $perpage = 20;
    $this->data['results'] = $this->Files_model->search_files('', $perpage,$offset);
        
    // Pagination
    $url =  $this->config->site_url();
    $pagination_config['base_url'] = $url.'admin/files/';
    $pagination_config['total_rows'] = count($this->Files_model->list_files());
    $pagination_config['per_page'] = $perpage;        
    $this->pagination->initialize($pagination_config);        
    $this->data['pagination'] = $this->pagination->create_links();
    $this->mysmarty->view('admin/files/welcome', $this->data);
}

And here is a basic model (Files_model) with the function search_files.
Code:
function search_files( $data='', $perpage, $offset='' )
{
    $this->db->select('files');
    $this->db->limit($perpage, $offset);
        
    $this->db->order_by('date', 'DESC');
    $query = $this->db->get('files');
    return $query->result_array();        
}

This should hopefully get you on the right track.

Bare in mind I am passing everything to the view including the pagnation create links.

Good Luck

Lee
#3

[eluser]Rubiz'[/eluser]
Oh! Big Grin it really solved my problem, thanx OES!!
#4

[eluser]satterle[/eluser]
OES:

I followed your directions exactly. I'm getting the proper perpage posts on the first page, but the page to page navigation doesn't display. On my view page, I have:

Code:
<?php
foreach ($content as $row) {
    $text = auto_link($row->n_text, 'url', TRUE);
    print nl2br($text);
}
print $pagination;
?>


Any suggestions?
#5

[eluser]OES[/eluser]
This normally means that your settings are incorrect for either the offset or the base url.

So first offset.

If you have for example:

domain.com/news/10

10 is your offest. So like my example your offset will be.

Code:
$offset = $this->uri->segment(2);

Then the base again make sure its pointing to the correcr area where pag will take place. ie.

Code:
$url =  $this->config->site_url();
  $pagination_config['base_url'] = $url.'news/';

Regards
#6

[eluser]satterle[/eluser]
Thanks, OES. Turns out I didn't *exactly* follow your directions...

Instead of

Code:
$pagination_config['total_rows'] = count($this->Files_model->list_files());

I had

Code:
$pagination_config['total_rows'] = count($data['results']);

Once I figured that one out, everything works fine.




Theme © iAndrew 2016 - Forum software by © MyBB