Vous êtes sur la page 1sur 17

MVC

CodeIgniter
Materi

1. Pendahuluan
2. Konsep MVC
3. Pemrograman MVC
4. Helper
5. Form
6. Library
7. Database
8. Session
The Model represents your data structures.
Typically your model classes will contain
functions that help you retrieve, insert, and
update information in your database.
The View is the information that is being
presented to a user
The Controller serves as an intermediary
between the Model, the View, and any other
resources needed to process the HTTP request
and generate a web page.
<?php
class Coba extends Controller {
function index() {
echo "Helo World";
}
}
?>
<?php <html>
class Coba extends Controller <head>
{ <title>Contoh
function index() { Penggunaan
$data['teks'] = "Helo World"; Views</title>
$this->load- </head>
>view('tampil',$data); <body>
} <?= $teks; ?>
} </body>
?> </html>
<?php
Class Model_coba extends Model {
function helo() {
$teks = "Helo World";
return $teks;
}
}
?>
<?php
class Coba extends Controller {
function index() {
$this->load->model('Model_coba','',TRUE);
$data['teks'] = $this->Model_coba->helo();
$this->load->view('tampil',$data);
}
}
?>
<?php <?php
class Coba extends Controller { Class Model_coba
function index() { extends Model {
$this->load-
>model('Model_coba','',TRUE); function helo() {
$data['teks'] = $this- $teks = "Helo
>Model_coba->helo(); World";
$this->load- return $teks;
>view('tampil',$data);
} }
} }
?> ?>
<html>
<head>
<title>Contoh Penggunaan Views</title>
</head>
<body>
<?= $teks; ?>
</body>
</html>
<?php
Class Db_model extends Model {
function __construct() {
parent::Model();
}
function ambil_data() {
$data_siswa = $this->db->query("SELECT * FROM siswa");
return $data_siswa;
}
}
?>
<?php
Class Siswa extends Controller {
function __construct() {
parent::Controller();
$this->load->database();
}
function index() {
$this->load->model('Db_model','',TRUE);
$data["data_siswa"] = $this->Db_model->ambil_data();
$this->load->view(v_siswa',$data);
}
}
?>
<html>
<head>
<title>Contoh Penggunaan fungsi result()</title>
<head>
<body>
<table border="1">
<tr><th>Id</th><th>Nama</th><th>Alamat</th><th>Kelas</th></tr>
<?php
foreach($data_siswa->result() as $row) {
?>
<tr><th><?=$row->id?></th><th><?=$row->nama?></th><th><?=$row-
>alamat?></th><th><?=$row->kelas?></th></tr>
<?php
}
?>
</table>
</body>
</html>

Vous aimerez peut-être aussi