0% found this document useful (0 votes)
5 views6 pages

BAB IV DatatabledanModel (Web) Fix

The document outlines the steps for creating a user table and model in a CodeIgniter application. It includes instructions for populating the user table, modifying configuration files, and implementing a data table in the view. Additionally, it provides code snippets for the model, controller, and view components necessary for displaying user data and handling file uploads.

Uploaded by

Julham Komara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views6 pages

BAB IV DatatabledanModel (Web) Fix

The document outlines the steps for creating a user table and model in a CodeIgniter application. It includes instructions for populating the user table, modifying configuration files, and implementing a data table in the view. Additionally, it provides code snippets for the model, controller, and view components necessary for displaying user data and handling file uploads.

Uploaded by

Julham Komara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

BAB IV

DATATABLES DAN MODEL

1. Buat table “User”

2. Isi tabel “user”

3. Atur Application config autoload.php ubah


4. Buat Model “Modeldb.php” pada folder application/models

<?php
class Modeldb extends CI_model{
public function get_all($table)
{
return $this->db->get($table);
}

public function get_data($limit,$start)


{
$query=$this->db->get('barang',$limit,$start);
return $query;
}
}
?>
5. Tambahkan code berikut pada controller/Inputuser.php

$data['user']=$this->Modeldb->get_all('user
')->result_array();
6. Buat Table dengan Data Table

<div id="layoutSidenav_content">
<main>
<div class="container-fluid px-4">
</div>
<div style="padding: 10px;">
<?php echo $this->session->flashdata('pesan'); ?>
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary"><?php echo $title ?></h6>
</div>
<div class="card-body">
<center>
<h3> Data User</h3>
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<td width="150">No.</td>
<td width="250">Nama</td>
<td width="200">Username</td>
<td width="200">Password</td>
<td>Level</td>
<td width="200">Aksi</td>
</tr>
</thead>
<tbody>
<?php $no=1; foreach ($user as $j):?>
<tr>
<td>
<?php echo $no++?>
</td>
<td><?php echo $j['name']?></td>
<td><?php echo $j['username']?></td>
<td><?php echo $j['password']?></td>
<td><?php echo $j['level']?></td>

<td width="150">
<a class="btn btn-sm btn-primary" href="<?php echo
base_url('admin/Tampiluser/updateData/'.$j['iduser']) ?>"><i class="fas fa-edit"></i></a>
<a class="btn btn-sm btn-primary" href="<?php echo
base_url('admin/Tampiluser/deleteData/'.$j['iduser']) ?>"><i class="fas fa-trash"></i></a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</center>

</div>
</div>

7. Atur bagian View/Templates_admin/footer.php dengan code berikut :

<!-- Page level plugins -->


<script src="<?php echo base_url();
?>/assets/vendor/datatables/jquery.dataTables.min.js"></script>
<script src="<?php echo base_url();
?>/assets/vendor/datatables/dataTables.bootstrap4.min.js"></script>
<!-- Page level custom scripts -->
<script src="<?php echo base_url(); ?>assets/js/demo/datatables-demo.js"></script>
8. Tambahkan dibagian view/templates_admin/header

<!-- Custom styles for this page -->


<link href="<?php echo base_url();
?>/assets/vendor/datatables/dataTables.bootstrap4.min.css" rel="stylesheet">

<link href="<?php echo base_url();


?>/assets/vendor/datatables/dataTables.bootstrap4.min.css" rel="stylesheet">

<script>
$(document).ready( function () {
$('#myTable').DataTable();
} );
</script>
<script>

$(document).ready(function(){
$('input[type="file"]').change(function(e){
var fileName = e.target.files[0].name;
alert('The file "' + fileName + '" has been selected.');
});
});
</script>

<script src="https://cdn.datatables.net/2.0.5/js/dataTables.js"></script>

<script>

$(document).ready(function(){
$('input[type="file"]').change(function(e){
var fileName = e.target.files[0].name;
alert('The file "' + fileName + '" has been selected.');
});
});
</script>
8. Jalankan localhost/penjualan/input data user

You might also like