- Loading Data...
Code : $code
"; echo "
Product Name : $name
"; }); $app->run();
=,0-")#' %)*# #%/,/ 8)# ?,+ +7@?/,7 ",'.#' ##* :**ASPP&@9#&:@/*P+,G#7F /&)0P8,'"@7P/&)0P/&)0PA7@"-9*P5\\_P3#+-' 0#%# #%#' 0-'9-& *#0A)' /,A,7*) ") +#?#: )')< 4,7"#A#* [ A#7#0,*,7 ") -7& *,7/,+-*; (#)*- %@", A7@"-% "#' '#0# A7@"-%< 5#7#0,*,7 )') +)/# ")-+#: /,/-#) %,+-*-:#' %)*#<
Y= ",:; /,'G-*'(# 0#7) %)*# 'G-*%#' %, '.%#:F'.%#: -'*-% 0,0+-#* /,+-#: 1234K-& !56 /,",7:#'# ",'.#' 3&)0 K7#0,?@7%< J)/)') /#(# 0,'.#0+)& /*-") %#/-/ /,+-#: *#+,& "#*# 9-/*@0,7< =)*# +-#* *,7&,+): "#:-&- *#+,&'(# /,A,7*) ") +#?#: )') S CREATE TABLE IF NOT EXISTS `tbl_customer` ( `id_customer` INT( 5 ) NOT NULL AUTO_INCREMENT , `nama_customer` VARCHAR( 100 ) NOT NULL , `alamat` TEXT NOT NULL , `telepon` VARCHAR( 50 ) NOT NULL , `tempat_lahir` VARCHAR( 100 ) NOT NULL , `tgl_lahir` VARCHAR( 100 ) NOT NULL , PRIMARY KEY ( `id_customer` )
) CREATE TABLE IF NOT EXISTS `tbl_api_reg` ( `id_api_reg` INT( 5 ) NOT NULL AUTO_INCREMENT , `email` VARCHAR( 50 ) NOT NULL , `api_key` VARCHAR( 50 ) NOT NULL , PRIMARY KEY ( `id_api_reg` )
)
=)*# /,")#%#' [ +-#: *#+,&; (#)*- *#+,& 9-/*@0,7 (#'. +,7)/)%#' "#*# A,'..#' "#' *#+,& #A) 7,.)/*7#*)@' (#'. +,7)/)%#' !56 %,( (#'. *,: *,7"#>*#7< N'*-% 0,'#0A)&%#' "#*# A,'..#'; %)*# :#7-/ 0,'(,7*#%#' !56 %,( (#'. *,: *,7"#>*#7 ") *#+,& #A) 7,.)/*7#*)@'< H#? 0)7)A /,A,7*) %,+#'(#%#' ?,+/)*, (#'. 0,'(,")#%#' !56 -'*-% A#7# ",8,&@A,7 &-#7< #< M-%# >)&, )'",I
setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); return $dbh; }
+< N'*-% #-*,'*)%#/) #A) %,(; %)*# +-#* /,+-#: 0,*:@" 8#&)"#*,!A)=,(Uc%,(W (#'. '#'*)'(# 0,*:@" )') #%#' %)*# A#'..)& ",'.#' 0)""&,?#7, (#'. ")/)/)A%#' 0,&-) 7@-*)'.< function validateApiKey($key) { $sql = "select * FROM tbl_api_reg where api_key='".$key."'"; $db = getConnection(); $sth = $db->prepare($sql); $sth->execute(); return $sth->rowCount(); } $authKey = function ($route) { $app = \Slim\Slim::getInstance(); $routeParams = $route->getParams(); if (validateApiKey($routeParams["key"])==0) { $app->halt(401); } };
9< 3,'G-*'(#; %)*# +-#* /,+-#: 7@-*, +#7- ",'.#' '#0# JF67?;=< (#'. #%#' 0,'#0A)&%#' /,&-7-: "#*# ") "# *#+,& *+&V9-/*@0,7< T)%# ")#%/,/ *#'A# !56 =,( #*#- !56 =,( *)"#% 8#&)"; 0#%# #%#' 0-'9-& *#0A)' %@/@'. ") +7@?/,7< J#' G)%# ")#%/,/ 0,&-) ,I*,'/)@' E:7@0, !"8#'9, 1234 E&),'*; #%#' 0-'9-& /*#*-/ RS3 T58F7U?<:V=P<
T)%# ")#%/,/ ",'.#' !56 =,( (#'. 8#&)"; 0#%# #%#' 0-'9-& /*#*-/ DSS 2$< J#' "#*# ")*#0A)&%#'<
$app->get('/customer/:key/', $authKey, function () use ($app) { $sql = "select * FROM tbl_customer "; try { $db = getConnection(); $stmt = $db->query($sql); $data = $stmt->fetchAll(PDO::FETCH_OBJ); $db = null; $app->response()->header('Content-Type', 'application/json'); echo '{"data": ' . json_encode($data) . '}'; } catch(PDOException $e) { echo '{"error":{"text":'. $e->getMessage() .'}}'; } });
T )%# )'.)' ")#%/,/ 8)# *,70)'#&P9@'/@&,; +)/# 0,'..-'#%#' A,7)'*#: S curl -i -X GET http://localhost/belajarslim/vendor/slim/slim/customer/d2ba5ac651d985a7fad886044d92b5cd
"< !"#%#'(# %)*# :#'(# )'.)' 0,'.#%/,/ /#*- +#7)/ "#*# /#G# +,7"#/#7%#' 6J; %)*# :#7-/ 0,0+-#* 7@-*)'. +#7- /,A,7*) ") +#?#: )')<
$app->get('/customer/:key/:id/', $authKey, function ($key,$id) use ($app) { try { $sql = "select * FROM tbl_customer where id_customer ='".$id."'"; $db = getConnection(); $stmt = $db->query($sql); $data = $stmt->fetch(PDO::FETCH_OBJ); $db = null; $app->response()->header('Content-Type', 'application/json'); echo '{"data": ' . json_encode($data) . '}'; } catch (Exception $e) { $app->response()->status(400); $app->response()->header('X-Status-Reason', $e>getMessage()); } });
E@'*@:'(# G)%# )'.)' 0,'.#%/,/ "#*# ",'#.' 6J d _; +)/# 0,'..-'#%#' A,7)'*#: +,7)%-* 8)# 9@'/@&, S curl -i -X GET http://localhost/belajarslim/vendor/slim/slim/customer/d2ba5ac651d985a7fad886044d92b5cd/1
,< 1@-*, ",'.#' 0,*:@" 5Y34 %)*# .-'#%#' -'*-% 0,'#0+#: "#*# %, "# *#+,&< J#*# "# >@70#* G/@' ") A-/: "#7) 9&),'* "#' ")*#'.%#A ",'.#' A,7)'*#: c#AAF e7,f-,/*UWg @&,: 1234K-& !56<
$app->post('/customer/:key/', $authKey, function () use ($app) { try { $request = $app->request(); $input = json_decode($request->getBody()); $sql = "INSERT INTO tbl_customer (nama_customer, alamat, telepon, tempat_lahir, tgl_lahir) VALUES (:nama_customer, :alamat, :telepon, :tempat_lahir, :tgl_lahir)"; $db = getConnection(); $stmt = $db->prepare($sql); $stmt->bindParam("nama_customer", $input->nama_customer); $stmt->bindParam("alamat", $input->alamat); $stmt->bindParam("telepon", $input->telepon); $stmt->bindParam("tempat_lahir", $input->tempat_lahir); $stmt->bindParam("tgl_lahir", $input->tgl_lahir); $stmt->execute(); $data = $db->lastInsertId(); $db = null; echo json_encode($input); } catch (Exception $e) { $app->response()->status(400); $app->response()->header('X-Status-Reason', $e->getMessage()); } });
curl -i -X POST -H 'Content-Type: apation/json' -d '{"nama_customer": "Dedek", "alamat": "Bandung", "telepon" : "083856764522" , "tempat_lahir" : "Jakarta" , "tgl_lahir" : "09/12/1978"}' http://localhost/belajarslim/vendor/slim/slim/customer/d2ba5ac651d985a7fad886044d92b5cd
><
N'*-% 0,%-%#' -A"#*, *,7:#"#A "#*#; %)*# +)/# 0,'..-'#%#' 0,*:@" 5N4< $app->put('/customer/:key/:id/', $authKey, function ($key,$id) use ($app) { try { $request = $app->request(); $input = json_decode($request->getBody()); $sql = "UPDATE tbl_customer set nama_customer=:nama_customer, alamat=:alamat, telepon=:telepon, tempat_lahir=:tempat_lahir, tgl_lahir=:tgl_lahir where id_customer='".$id."'"; $db = getConnection(); $stmt = $db->prepare($sql); $stmt->bindParam("nama_customer", $input->nama_customer); $stmt->bindParam("alamat", $input->alamat); $stmt->bindParam("telepon", $input->telepon); $stmt->bindParam("tempat_lahir", $input->tempat_lahir); $stmt->bindParam("tgl_lahir", $input->tgl_lahir); $stmt->execute(); $db = null; echo json_encode($input); } catch (Exception $e) { $app->response()->status(400); $app->response()->header('X-Status-Reason', $e>getMessage()); } });
curl -i -X PUT -H 'Content-Type: appation/json' -d '{"nama_customer": "Dedek Irawan", "alamat": "Bandung", "telepon" : "083856764522" , "tempat_lahir" : "Jakarta" , "tgl_lahir" : "09/12/1978"}' http://localhost/belajarslim/vendor/slim/slim/customer/d2ba5ac651d985a7fad886044d92b5cd/5
.< J#' G)%# )'.)' 0,'.:#A-/ "#*#; %)*# "#A#* 0,'..-'#%#' 0,*:@" J2Z242 $app->delete('/customer/:key/:id/', $authKey, function ($key,$id) use ($app) { try { $sql = "DELETE FROM tbl_customer WHERE id_customer='".$id."'"; $db = getConnection(); $stmt = $db->prepare($sql); $stmt->bindParam("id", $id); $stmt->execute(); $db = null; } catch (Exception $e) { $app->response()->status(400); $app->response()->header('X-Status-Reason', $e>getMessage()); } });
curl -i -X DELETE http://localhost/belajarslim/vendor/slim/slim/customer/d2ba5ac651d985a7fad886044d92b5cd/5
:< T#'.#' &-A# -'*-% 0,'#0+#:%#' A,7)'*#: c#AAFe7-'UWg -'*-% 0,'.,%/,%-/) /,0-# 7@-*)'. (#'. /-"#: %)*# +-#* *#")<
^#:; 9-%-A 0-"#: %#' -'*-% 0,0+-#* /,+-#: 1234K-& !56 ",'.#' 3&)0 K7#0,?@7%;;;hh 3,%#7#'. 0,0#'. .) %,7,'F%,7,'i'(# #A&)%#/) (#'. ")+#'.-' ",'.#' 1234K-& !56; %#7,'# ",'.#' +,.)*- *#7.,* #A&)%#/) ") 9&),'* +)/# +,70#9#0F0#9#0< M)/# ")+-#* %, #A&)%#/) 0@+)&,; ",/%*@A +#:%#' ?,+< 3,+,'#7'(# A#"# #A&)%#/) )') +)/# %)*# *#0+#:%#' #-*,'*)%#/) *#0+#:#'; ")0#'# -/,7 (#'. )'.)' 0,'.#%/,/ "#*# "#7) 1234 !56 :#7-/ &@.)' *,7&,+): "#:-&-< C@'..@ %#?#'F%#?#' (#'. 0,'#0+#:%#'< 3,+,'#7'(# *#") /-"#: /,0A#* /#(# *#0+#:%#'; 9-0# #.#% %,/-&)*#' 0,'9@+#'(# 0,&-) ,I*,'/)@' 9:7@0, !"8#'9, 1,/* E&),'*<
W4 );C9=;=5786: #".,0F9 &G) T57F@ &C9:@86: B9:=57 3,*,: 0,0+-#* 1234K-& !56; /,%#7#'. '.%#: /,'G-*'(# #"#: 0,0+-#* #A&)%#/) ") /)/) 9&),'*< 60A&,0,'*#/)'(# *,7/,7#: +)/# 0,'..-'#%#' +#:#/# A,[email protected]#0#' #A#A-'; %#7,'# :#/)& @-*A-* "#7) 1234K-& !56 )') +,7-A# >@70#* T3Y^ (#'. 7#*#F7#*# +)/# ")FA#7/)'. @&,: 0#/)'.F0#/)'. +#:#/# A,[email protected]#0#' 0@",7'< N'*-% 9@'*@: )0A&,0,'*#/)'(#; /#(# ")/)') 0,'..-'#%#' :*0&j#G#IjGk-,7(< #< M-#* /,+-#: >)&, :*0& /,A,7*) ") +#?#: )')
+< 3,%#7#'. %)*# #%#' 0,0+-#* /,+-#: >)&, (#'. +,7)/)%#' %@", G#8#/97)A* -'*-% *,7:-+-'. ",'.#' 1234 !56 8)# #G#I (#'. *,: %)*# +-#* /,+,&-0'(#< J)/)') /#(# *)"#% #%#' 0,0+#:#/ &,+): ",*#)& *,'*#'. #G#I< var URL = "http://localhost/belajarslim/vendor/slim/slim/customer/d2ba5ac651d985a7fad886044d92b5cd"; showAllData(); $('#DeleteBtn').hide(); $('#ListData a').live('click', function() { selectData($(this).data('identity')); }); $('#AddBtn').click(function() { newData(); return false; }); $('#SaveBtn').click(function() { if ($('#id').val() != '') { updateData(); } else { addData(); } return false; }); $('#DeleteBtn').click(function() { deleteData(); return false; }); function newData() { $('#DeleteBtn').hide(); setDetail({}); } function showAllData() { $.ajax({ type: 'GET', url: URL, dataType: "json", success: setDataList }); } function selectData(id_customer) { $.ajax({ type: 'GET', url: URL + '/' + id_customer, dataType: "json", success: function(customer){ $('#DeleteBtn').show(); console.log('selectData success: ' + customer.id_customer); setDetail(customer); } }); }
function addData() { $.ajax({ type: 'POST', contentType: 'application/json', url: URL, dataType: "json", data: parseToJson(), success: function(data, status, jqXHR){ $('#DeleteBtn').show(); $('#id').val(data.id_customer); showAllData(); }, error: function(jqXHR, status, errorThrown){ alert('addData error: ' + status); } }); } function updateData() { $.ajax({ type: 'PUT', contentType: 'application/json', url: URL + '/' + $('#id').val(), dataType: "json", data: parseToJson(), success: function(data, status, jqXHR){ showAllData(); }, error: function(jqXHR, status, errorThrown){ alert('updateData error: ' + status); } }); } function deleteData() { $.ajax({ type: 'DELETE', url: URL + '/' + $('#id').val(), success: function(data, status, jqXHR){ showAllData(); setDetail({}); $('#DeleteBtn').hide(); }, error: function(jqXHR, status, errorThrown){ alert('deleteData error'); } }); } function setDetail(customer) { $('#id').val(customer.id_customer); $('#nama_customer').val(customer.nama_customer); $('#alamat').val(customer.alamat); $('#telepon').val(customer.telepon); $('#tempat_lahir').val(customer.tempat_lahir); $('#tgl_lahir').val(customer.tgl_lahir); }
function setDataList(data) { var datalist = data == null ? [] : (data.customer instanceof Array ? data.customer : [data.customer]); $('#ListData li').remove(); $.each(datalist, function(index, customer) { $('#ListData').append('
9< 5#"# N1Z; G#'.#' &-A# 0,'#0+#:%#' !56 =,( (#'. /-"#: *,7"#>*#7 ") "# *#+,& #A) %,(< T)%# ")G#'%#' 8)# +7@?/,7; 0#%# :#/)&'(# #%#' /,A,7*) ") +#?#: )') S
C#/): +#'(#% >)*-7F>)*-7 "#7) 3&)0 >7#0,?@7% (#'. +)/# "))0A&,0,'*#/)%#' -'*-% 0,0+-#* /,+-#: 1234K-& !56 /,78)9,/< 3,A,7*) 0,'#0+#:%#' #-*,'*)%#/) #A#%#: -/,7 /-"#: &@.)' #*#- +,&-0 %,*)%# #%#' 0,'.#%/,/ /-#*- -7& (#'. %:-/-/< Y= ",:; /,%)#' "-&- #7*)%,& *,'*#'. 3&)0 >7#0,?@7% %#&) )')< 3,0@.# +,70#'>##* -'*-% 7,%#'F7,%#' !
+?>59?8P .?F
:**A/SPP.)*:-+<9@0P.,",&-0+-'.P3&)0E1NJE&),'*
G:Y8Z8[H;8:94J?; 1=E6:7= X U77CXLLH=P=9F;EF5H4J?;