resources.php
1.91 KB
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
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require APPPATH.'/libraries/REST_Controller.php';
// use Restserver\Libraries\REST_Controller;
class Resources extends REST_Controller {
function __construct($config = 'rest') {
parent::__construct($config);
$this->load->database();
}
function index_get() {
$id = $this->get('id');
if ($id == '') {
$kontak = $this->db->get('pmlocal_jenissdy')->result();
} else {
$this->db->where('id_jenissdy', $id);
$kontak = $this->db->get('pmlocal_jenissdy')->result();
}
$this->response($kontak, 200);
}
function index_post() {
$data = array(
'id' => $this->post('id'),
'nama' => $this->post('nama'),
'nomor' => $this->post('nomor'));
$insert = $this->db->insert('telepon', $data);
if ($insert) {
$this->response($data, 200);
} else {
$this->response(array('status' => 'fail', 502));
}
}
function index_put() {
$id = $this->put('id');
$data = array(
'id' => $this->put('id'),
'nama' => $this->put('nama'),
'nomor' => $this->put('nomor'));
$this->db->where('id', $id);
$update = $this->db->update('telepon', $data);
if ($update) {
$this->response($data, 200);
} else {
$this->response(array('status' => 'fail', 502));
}
}
function index_delete() {
$id = $this->delete('id');
$this->db->where('id', $id);
$delete = $this->db->delete('telepon');
if ($delete) {
$this->response(array('status' => 'success'), 201);
} else {
$this->response(array('status' => 'fail', 502));
}
}
}
?>