Anda di halaman 1dari 5

Contoh Code Program

Code program ini adalah salah satu code yang ada di folder model, view dan controller
yang digunakan untuk menampilkan seluruh data pada tabel t_layanan

1. C_layanan.php (pada folder controller)


<?php if (!defined('BASEPATH')) exit('No direct access allowed');

class c_layanan extends CI_Controller{

function __construct(){

parent::__construct();

$this->load->model('admin/m_layanan');

$this->load->helper('form','url');

session_start();

public function index(){

$session=isset($_SESSION['admin_barang_telkom']) ?
$_SESSION['admin_barang_telkom']:'';

if($session!=""){

$data['title'] = 'Data Layanan';

$offset = $this->uri->segment(4, 0);

$total = 5;

$result = $this->m_layanan->get_all_layanan($offset, $total);

$pagination['base_url'] = base_url().'admin/c_layanan/index/';

$pagination['total_rows'] = $result['total_rows'];

$pagination['full_tag_open'] = "<ul class='pagination pagination-


sm' style='position:relative; top:-25px;'>";
2. M_layanan.php (pada folder models)
<?php

class m_layanan extends CI_Model{

function __construct(){

parent::__construct();

function get_all_layanan($offset, $total){

$result['total_rows'] = $this->db->count_all_results('t_layanan');

$this->db->select('*');

$this->db->from('t_layanan');

$query = $this->db->get('', $total, $offset);

$result['data'] = $query->result();

return $result;

}
3. V_layanan (pada folder view)
<?php $this->load->view('admin/header'); ?>

<p><?=$this->session->flashdata('pesan')?> </p>

<p><br><a href="<?= base_url()?>admin/c_layanan/addLayanan"class="btn btn-sm


btn-primary"><i class="glyphicon glyphicon-plus"></i> Tambah Data</a></br></p>

<?php

if(count($listLayanan)> 0){

?>

<div class="dataTable_wrapper">

<table class="table table-striped table-bordered table-hover" id="dataTables-example">

<thead>

<th>No</th>

<th>Layanan</th>

<th>Action</th>

</thead>
<tbody>

<?php

$no=0;

foreach ($listLayanan as $a) {

$no++;

?>

<tr>

<td><?= $no ?></td>

<td><?= $a->nama_layanan ?></td>

<td><a href="<?= base_url()


?>admin/c_layanan/updateLayanan/<?= $a->id_layanan?>"class="btn btn-success btn-sm"><i
class="glyphicon glyphicon-pencil"></i></a>

| <a href="<?= base_url()


?>admin/c_layanan/deleteLayananDb/<?= $a->id_layanan?>" class="btn btn-danger btn-sm"
onclick="return confirm('Anda Yakin menghapus data ini?')"><i class="glyphicon glyphicon-
trash"></i></a>

</td>

</tr>

<?php

?>

</tbody>

</table>

<?php

echo $halaman;

$this->load->view('admin/footer');

?>