Membuat Pagination di CodeIgniter Dengan Mudah
CodeIgniter merupakan framework php yang sangat mudah digunakan untuk pemula,
mudah digunakan karena banyak fitur.
Salah satu fitur yang menarik adalah pagination, saya akan memberikan tutorialnya sesuai dokumentasinya
https://codeigniter.com/userguide3/libraries/pagination.html
Pertama di model kita harus membuat sebuah fungsi dengan parameter limit dan start seperti ini
function getdatalimit($limit, $start){
$data=$this->db->get('tb_list_data_testing', $limit, $start);
return $data;
}
ketika di controllernya kita harus load library pagination seperti berikut, di source code ini sudah termasuk css boostrap v4
//pagination
$this->load->library('pagination');
//config
$config['base_url'] ='http://localhost/klasifikasidesapadi/admin/datatesting/index';
$config['total_rows'] = $this->Model->countdata();
$config['per_page'] = 12;
$config['first_link'] = 'First';
$config['last_link'] = 'Last';
$config['next_link'] = 'Next';
$config['prev_link'] = 'Prev';
$config['full_tag_open'] = '<div class="pagging text-center"><nav><ul class="pagination justify-content-center">';
$config['full_tag_close'] = '</ul></nav></div>';
$config['num_tag_open'] = '<li class="page-item"><span class="page-link">';
$config['num_tag_close'] = '</span></li>';
$config['cur_tag_open'] = '<li class="page-item active"><span class="page-link">';
$config['cur_tag_close'] = '<span class="sr-only">(current)</span></span></li>';
$config['next_tag_open'] = '<li class="page-item"><span class="page-link">';
$config['next_tagl_close'] = '<span aria-hidden="true">»</span></span></li>';
$config['prev_tag_open'] = '<li class="page-item"><span class="page-link">';
$config['prev_tagl_close'] = '</span>Next</li>';
$config['first_tag_open'] = '<li class="page-item"><span class="page-link">';
$config['first_tagl_close'] = '</span></li>';
$config['last_tag_open'] = '<li class="page-item"><span class="page-link">';
$config['last_tagl_close'] = '</span></li>';
// initinalzie
$this->pagination->initialize($config);
$datacontent['start'] = $this->uri->segment(4); //ambil index data ke
$datacontent['datatable']=$this->Model->getdatalimit($config['per_page'],$datacontent['start']);
Ketika di view tinggal kita tambahkan seperti ini dibawah table
<?=$this->pagination->create_links();?>
Pagination akan otomatis tergenerate.
Hasilnya seperti ini
Post a Comment for "Membuat Pagination di CodeIgniter Dengan Mudah"