Pagination in Kohana 3.2
September 20, 2011
Unfortunately Kohana 3.2 dropped the pagination module. Usually updates just extend the current features so not sure why they removed the functionality. It may have had pure MVC concepts but it was a nice feature.
However, getting the results in orm for a pagination is still pretty simple. First add the route that will pass the page number from the friendly URL.
Route::set('pagi_page', 'welcome/index(/)')
->defaults(array(
'controller' => 'welcome',
'action' => 'index',
'page' => '1'
));
Next set up the limits in your controller action:
public function action_index()
{
$limit = 30; //change this to the number of results you want.
$page_number = $this->request->param('page');
$offset = $limit * ($page_number-1);
}
And then just use those variables to manipulate the ORM to get the expected results.
public function action_index()
{
$limit = 30; //change this to the number of results you want.
$page_number = $this->request->param('page');
$offset = $limit * ($page_number-1);
$results = ORM::factory('items')->limit($limit)->offset($offset)->find_all();
}