142
2 3
4 5
6 7
8 9
10 11
html lang
= en
head meta
charset =
utf-8 meta
name =
viewport content
= width=device-width, initial-scale=1
title Dashboard Admin
title -- Bootstrap core CSS --
link href
= ?php
echo base_url
? assetscssbootstrap.min.css
rel =
stylesheet link
href =
?php echo
base_url ?
assetsstyledashboard.css rel
= stylesheet
head body
... kode sesudah ...
2. Buat controller Admin.php dalam folder controllers, tulis kode dibawah
ini
C:xampphtdocsmyproyekapplication
1 2
3 4
5 6
7 8
9 10
?php defined
BASEPATH ORexit
No direct script access allowed ;
class Admin
extends CI_Controller
{ publicfunction
index {
this -
load -
model web_model
; data
[ artikel
]= this
- web_model
- get_data_artikel
; this
- load
- view
dashboard ,
data ;
} }
4.
Buka kembali file dashboard.php, rubah kode seperti dibawah ini,
kode ini digunakan untuk menampilkan data yang ada dalam database yang telah disimpan dalam sebuah tipe data array.
C:xampphtdocsmyproyekapplication
52 53
54 55
56 57
58 59
60 61
62 63
64 65
66 67
68 69
50 ... kode sebelum ...
div class
= table-responsive
table class
= table table-striped
thead tr
th width
= 5
th th
width =
20 Judul
th th
width =
60 Konten
th th
width =
5 Aksi
th th
width =
5 th
tr thead
?php nomer
= 1
;? tbody
?php foreach
artikel as
data_artikel :?
tr td
?php echo
nomer ;?
td td
?php echo
data_artikel -
judul ;?
td td
?php echo
data_artikel -
konten ;?
td
143
51 52
53 54
55 56
57 tda
href =
class =
btn btn-
info Update
atd tda
href =
class =
btn btn-
danger Hapus
atd tr
tr ?php
nomer ++?
?php endforeach
? tbody
table div
... kode sesudah ... 5.
Akses web dengan URL http:localhostmyproyekindex.phpadmin
6.
Jalankan program tampilkan dan analisa hasilnya
4. Membangun form tambah artikel pada halaman admin:
1. Buka file form_artikel.html, rubah beberapa kode seperti dibawah ini, simpan dengan nama form_artikel.php dalam folder application views
C:xampphtdocsmyproyekapplication
1 2
3 4
5 6
7 8
9 10
52 53
54 55
56 57
58 59
60 DOCTYPE html
html lang
= en
head meta
charset =
utf-8 meta
name =
viewport content
= width=device-width, initial-scale=1
title Dashboard Admin
title -- Bootstrap core CSS --
link href
= ?php
echo base_url
? assetscssbootstrap.min.css
rel =
stylesheet link
href =
?php echo
base_url ?
assetsstyledashboard.css rel
= stylesheet
head ... kode antara ...
form action
= ?php
echo base_url
? index.phpadmindo_tambah
method =
POST div
class =
form-group label
Judul Artikel label
input type
= text
name =
judul class
= form-
control placeholder
= Judul artikel
div div
class =
form-group label
Konten label
textarea name
= konten
class =
form- control
rows =
12 textarea
div button
type =
submit class
= btn btn-primary
Simpan button
button type
= submit
class =
btn btn-danger Cancel
button form
2. Tambahkan kode seperti dibawah ini dalam class Admin file Admin.php