forked from fakhrulnugroho/rental-mobil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC_Merk.php
75 lines (64 loc) · 1.78 KB
/
C_Merk.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
class C_Merk extends Controller {
public function __construct(){
$this->addFunction('url');
if(!isset($_SESSION['login'])) {
$_SESSION['error'] = 'Anda harus masuk dulu!';
header('Location: ' . base_url());
}
$this->addFunction('web');
$this->addFunction('session');
$this->req = $this->library('Request');
$this->merk = $this->model('M_Merk');
}
public function index(){
$data = [
'aktif' => 'merk',
'judul' => 'Data Merk',
'data_merk' => $this->merk->lihat(),
'no' => 1
];
$this->view('merk/index', $data);
}
public function tambah(){
if(!isset($_POST['tambah'])) redirect('merk');
$merk = $this->req->post('merk');
if($this->merk->tambah($merk)){
setSession('success', 'Data berhasil ditambahkan!');
redirect('merk');
} else {
setSession('error', 'Data gagal ditambahkan!');
redirect('merk');
}
}
public function ubah($id){
if(!isset($id) || $this->merk->cek($id)->num_rows == 0) redirect('merk');
$data = [
'aktif' => 'merk',
'judul' => 'Ubah Merk',
'merk' => $this->merk->lihat_id($id)->fetch_object(),
];
$this->view('merk/ubah', $data);
}
public function proses_ubah($id){
if(!isset($id) || $this->merk->cek($id)->num_rows == 0 || !isset($_POST['ubah'])) redirect('merk');
$merk = $this->req->post('merk');
if($this->merk->ubah($merk, $id)){
setSession('success', 'Data berhasil diubah!');
redirect('merk');
} else {
setSession('error', 'Data gagal diubah!');
redirect('merk');
}
}
public function hapus($id = null){
if(!isset($id) || $this->merk->cek($id)->num_rows == 0) redirect('merk');
if($this->merk->hapus($id)){
setSession('success', 'Data berhasil dihapus!');
redirect('merk');
} else {
setSession('error', 'Data gagal dihapus!');
redirect('merk');
}
}
}