141
5. Buka Web.php pada controllers, ubah code menjadi dibawah ini.
C:xampphtdocsmyproyekapplication
1 2
3 4
5 6
7 8
9 10
11 12
?php defined
BASEPATH ORexit
No direct script access allowed ;
class Web
extends CI_Controller
{ publicfunction
index {
this -
load -
model web_model
; data
[ artikel
]= this
- web_model
- get_data_artikel
; this
- load
- view
home ,
data ;
} }
6. Buka home.php pada folder views, rubah kode menjadi seperti
dibawah ini.
C:xampphtdocsmyproyekapplication
104 105
106 107
108 109
110 111
112 113
114 115
116 117
118 119
120 ... kode sebelum ...
div class
= col-sm-8 blog-main
?php foreach
artikel as
data_artikel :?
div h2
?php echo
data_artikel -
judul ;?
h2 p
?php echo
data_artikel -
waktu ;?
by a
href =
Iswanul Umam
ap p
?php echo
data_artikel -
konten ;?
p div
-- .blog-post -- ?php
endforeach ?
nav ul
class =
pager lia
href =
Previous ali
lia href
= Next
ali ul
nav div
-- .blog-main -- ... kode sesudah ...
7. Akses web dengan URL http:localhostmyproyek
8. Jalankan program di web browser tampilkan dan analisa hasilnya..
4.
Membangun web dinamis halaman admin, Langkah-langkah yang dilakukan untuk mebangun web dinamis anatra laian
adalah sebagai berikut: 1. Buka file dashboard.html, rubah beberapa kode program menjadi
seperti dibawah ini. Simpan dengan namadashboard.phpdalam
folder views
C:xampphtdocsmyproyekapplication
1 DOCTYPE html
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