Pagination Class
The pagination class allows you to easily setup pagination for records you display.
How To
A simple example on how to use the Pagination class, the set_config method is used in this example. You can put this inside your action methods in your controller.
$config = array(
'pagination_url' => 'http://localhost/fuel/welcome/index/',
'total_items' => 10,
'per_page' => 5,
'uri_segment' => 3,
);
// Config::set('pagination', $config); // you can use this too!
Pagination::set_config($config);
$data['example_data] = DB::select('id', 'value')->from('pagination')
->limit(Pagination::$per_page)
->offset(Pagination::$offset)
->execute()
->as_array();
$data['pagination'] = Pagination::create_links();
$this->render('welcome/index', $data);
Configuration
You can configure the pagination using two methods either by using the set_config method or by setting a global config array.
The following configuration settings can be defined:
pagination_url |
string |
None |
The URL of page where you have pagination.
|
uri_segment |
integer |
3
|
The URI segment containing the page number.
|
num_links |
integer |
5
|
The total number of links to show.
|
total_items |
integer |
0
|
The total number of items.
|
total_pages |
integer |
0
|
The total number of pages.
|
per_page |
integer |
10
|
The number of items per page.
|
Global Config Array
This method allows you to set the pagination configuration by setting a global config array.
Config::set('pagination', array(
'pagination_url' => 'http://fuelphp.com/docs/',
'uri_segment' => 2,
'total_items' => 10,
'per_page' => 20,
));
set_config(array $config)
The set_config method allows you to set the pagination configuration by passing an array.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$config |
Required |
The configuration array. |
|
Returns |
void |
Example |
Pagination::set_config(array(
'pagination_url' => 'http://fuelphp.com/docs/',
'uri_segment' => 2,
'total_items' => 10,
'per_page' => 20,
));
|
create_links()
The create_links method generates the pagination links in the view.
Static |
Yes |
Parameters |
None |
Returns |
mixed |
Example |
echo Pagination::create_links();
|
next_link($value)
The next_link method displays a "Next" link for pagination.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$value |
Required |
The text displayed in the link. |
|
Returns |
mixed |
Example |
echo Pagination::next_link('Next Page');
|
prev_link($value)
The prev_link method displays a "Previous" link for pagination.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$value |
Required |
The text displayed in the link. |
|
Returns |
mixed |
Example |
echo Pagination::prev_link('Previous Page');
|