Pagination Class¶
The Pagination class provides functionality that allows you to navigate from page to page.
Calling the Pagination Class¶
$Pagination = $this->Pagination;
Creating Pagination¶
Here is a simple example showing how to create pagination:
1. Getting pagination info:
$pagination = $this->Pagination->get(array(
//The name of the page in URL
'page_param' => 'page', //Example URL: http://www.example.com/index.php/bulletins/page2/
//This number represents the total rows in the result set you are creating pagination for.
//Typically this number will be the total rows that your database query returned.
'total_items' => 30,
//Title prefix
'title' => 'New Bulletins', //Example: New Bulletins: Page 2 (If empty result will be: Page 2)
//Pages URL template
'tpl_url' => 'http://www.example.com/index.php/bulletins/{page}/', //{page} will be replaced with 'page_param' and page number
//The number of items you intend to show per page
'items_per_page' => 10,
//The number of pagination items
'num_page_items' => 5
));
2. Assigning $pagination variable:
$this->View->assign('pagination', $pagination);
3. Putting pagination code to template file:
{display file="pagination" pagination=$pagination}
4. Displaying template file:
$this->View->display('new-bulletins');
Calculating Values for LIMIT Clause¶
Using pagination values in LIMIT Clause:
$results_per_page = 10; //The number of items you intend to show per page
$limit = $this->Pagination->getLimit($results_per_page); //LIMIT values
$db = $this->select(array('b.*'))
->from(array('b' => 'bulletin_board_bulletins'))
->limit($limit);
Note: LIMIT values changes every time while you changing the pages.