It's a pagination library for CodeIgniter 2. Most of the code was moved from controller to the library, easy to config and create the pagination.
- application
- controllers
- pagination.php
- libraries
- lib_pagination.php
- views
- paging_sample.php
- controllers
- Sql
- paging.sql
- .htaccess
- Copy the paging.sql in sql folder, and import to your database. (It's for create a table named wp_posts)
- Copy .htaccess and all file to your codeigniter. (optional)
- Copy pagination.php sample code to yout controllers folder.
- Copy lib_pagination.php sample code to yout libraries folder.
- Copy paging_sample.php sample code to yout views folder.
- Run your page : http://yourdomain/yourciroot/pagination/index
(For e.g. : http://localhost/ci/sample/pagination/index)
public function index(){
$this->load->library('lib_pagination');
$pg_config['sql'] = "SELECT * from wp_posts";
$pg_config['per_page'] = 5;
$data = $this->lib_pagination->create_pagination($pg_config);
$this->load->view("paging_sample", $data);
}
$pg_config['sql'] Value of $pg_config['sql'] is your sql statement but rememeber the statements must without ; since the library would add something after you sql.
$pg_config['per_page'] This value is for showing how many record per page, must be an integer. If the value is 5, means display 5 items per page.
<?php
if (!empty($results['results'])){
foreach($results['results'] as $data) {
echo ".$data->id." ) ".$data->post_date."</div>";
}
}
?>
<p>Pagination: <?php echo $links; ?></p>
To display pagination bar at your view, use this code and place to somewhere you wanted to display.
This part is optional, for removing the index.php? of your url. You can just copy all code in .htaccess placing in the root of this project. For example:
From : http://soyosolution.com/index.php?/pagination/index/5 To : http://soyosolution.com/pagination/index/5
Suupose you run the code in localhost and install CodeIgniter in a folder named "ci": http://localhost/ci/sample/pagination/index Or you can run demo on our website: http://soyosolution.com/index.php?/pagination/index
http://soyosolution.com/pagination/index
The config of pagination bar 's appearance was paged in "/application/libraries/lib_pagination.php", arround line 28 - line 51, You can change appearance of pagination bar by uncomment and chnaging these value:
//Uncomment to config to your own pagination style.
/*
$config['first_link'] = 'First'; //The text you would like shown in the "first" link on the left. If you do not want this link rendered, you can set its value to FALSE.
$config['first_tag_open'] = '<span>'; //The opening tag for the "first" link.
$config['first_tag_close'] = '</span>';//The closing tag for the "first" link.
$config['last_link'] = 'Last'; //The text you would like shown in the "last" link on the right. If you do not want this link rendered, you can set its value to FALSE.
$config['last_tag_open'] = '<span>'; //The opening tag for the "last" link.
$config['last_tag_close'] = '</span>'; //The closing tag for the "last" link.
$config['next_link'] = '>'; //The text you would like shown in the "next" page link. If you do not want this link rendered, you can set its value to FALSE.
$config['next_tag_open'] = '<span>'; //The opening tag for the "next" link.
$config['next_tag_close'] = '</span>'; //The closing tag for the "next" link.
$config['prev_link'] = '<'; //The text you would like shown in the "previous" page link. If you do not want this link rendered, you can set its value to FALSE.
$config['prev_tag_open'] = '<span>'; //The opening tag for the "previous" link.
$config['prev_tag_close'] = '</span>'; //The closing tag for the "previous" link.
$config['cur_tag_open'] = '<b>'; //$config['cur_tag_open'] = '<b>';
$config['cur_tag_close'] = '</b>'; //$config['cur_tag_close'] = '</b>';
$config['num_tag_open'] = '<span>'; //The opening tag for the "digit" link.
$config['num_tag_close'] = '</span>'; //The closing tag for the "digit" link.
*/
$results | An object storing the result. |
$pagination | This value storing all the pagination code, place it to somewhere you want show the pagination bar. |
$result_amount | It's a integer storing the result records of your sql. |
<?php <h1 style="text-align:center">CodeIgniter Pagination Library Demo</h1> <table width="400" border="1" align="center"> <tr> <td width="100" bgcolor="#CCCCCC"><p>ID</p></td> <td width="300" bgcolor="#CCCCCC">Post Date</td> <td width="300" bgcolor="#CCCCCC">Post Title</td> </tr> <h1 style="text-align:center"></h1> <div id="body">
<i class="s"><?php foreach($results as $data) { ?></i> <tr> <td><?php echo $data->id; ?></td> <td><?php echo $data->post_date; ?></td> <td><?php echo $data->post_title; ?></td> </tr> <i class="s"><?php } ?></i> </table> <div style="text-align:center"><i class="s"><?php echo $pagination; ?></i></div> <div style="text-align:right">Total records: <i class="s"><?php echo $result_amount; ?></i>&</div>
</div>
04/12/2014
- Fix bugs if url end is not with '/', or number.
04/12/2014 Release CodeIgniter-pagination-library v2
- Rewrite the library and sample referenced by a codeigniter basic tutorial at codesamplez.com
- auto count the segment number for configuration
- auto change pagination link if it's the first page
- inclucde the all pagination code into a value named $links
30/06/2014 Release CodeIgniter-pagination-library v1
Codeigniter Offical Site
http://ellislab.com/codeigniter/user-guide/libraries/pagination.html
http://codesamplez.com/development/codeigniter-basic-tutorial
Pagination Sample Site:
http://soyosolution.com/en/works/1/
http://soyosolution.com/pagination/index
Library Site:
http://tool.soyosolution.com/codeIgniter-pagination-library/