Skip to content

Instantly share code, notes, and snippets.

@panbanda
Created March 12, 2012 20:24
Show Gist options
  • Save panbanda/2024462 to your computer and use it in GitHub Desktop.
Save panbanda/2024462 to your computer and use it in GitHub Desktop.
Kohana 3.x ORM Pagination
<?php
// Establish search query
$search = ORM::factory('blog');
// Get search total
$total = $search->reset(FALSE)->count_all();
// Create pagination
$pagination = Pagination::factory(array(
'current_page' => array('source' => 'route', 'key' => 'page'),
'total_items' => $total,
'items_per_page' => 15,
));
// Process results
$results = $search->limit($pagination->items_per_page)
->offset($pagination->offset)
->find_all();
$this->view->set('results', $results)
->set('pagination', $pagination);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment