Create a new file in a folder -> Controller
1 |
/application/controller/pagination.php |
Write Code like this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<?php class Pagination extends CI_Controller { function index() { $this->load->library('pagination'); $this->load->library('table'); $this->table->set_heading('Id', 'Judul', 'Isi'); $config['base_url'] = 'http://localhost/ci/index.php/pagination/index'; $config['total_rows'] = $this->db->get('pagination')->num_rows(); $config['per_page'] = 10; $config['num_links'] = 20; $config['full_tag_open'] = '<div id="pagination">'; $config['full_tag_close'] = '</div>'; $this->pagination->initialize($config); $data['records'] = $this->db->get('pagination', $config['per_page'], $this->uri->segment(3)); $this->load->view('pagination_view', $data); } } |
Create a new file in a folder -> Views
1 |
/application/views/pagination_view.php |
Write Code like this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <style type="text/css" media="screen"> #container { width: 600px; margin: auto; } table { width: 600px; margin: 10px; } td { border-right: 1px solid #aaaaaa; padding: 8px; } td:last-child { border-right: none; } th { text-align: left; padding-left: 1em; background: #cac9c9; border-bottom: 1px solid white; border-right: 1px solid #aaaaaa; } #pagination a, #pagination strong { background: #e3e3e3; padding: 4px 7px; text-decoration: none; border: 1px solid #cac9c9; color: #292929; font-size: 13px; } #pagination strong, #pagination a:hover { font-weight: normal; background: #cac9c9; } </style> </head> <body> <h1>Pagination CodeIgniter</h1> <div id="container"> <?php echo $this->table->generate($records); ?> <?php echo $this->pagination->create_links(); ?> </div> </body> </html> |