Welcome Guest, Not a member yet? Register   Sign In

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 :-)


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.
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->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.
function search_files( $data='', $perpage, $offset='' )
    $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


Oh! Big Grin it really solved my problem, thanx 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:

foreach ($content as $row) {
    $text = auto_link($row->n_text, 'url', TRUE);
    print nl2br($text);
print $pagination;

Any suggestions?

This normally means that your settings are incorrect for either the offset or the base url.

So first offset.

If you have for example:


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

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

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

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


Thanks, OES. Turns out I didn't *exactly* follow your directions...

Instead of

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

I had

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

Once I figured that one out, everything works fine.

Theme © iAndrew 2016 - Forum software by © MyBB