我必須在Rest服務中爲移動應用程序(iPhone和Android)創建一個Web服務。此應用程序基於一個電子出版。我嘗試一些基於SLIM的REST服務。我可以將數據添加到數據庫並從數據庫中檢索數據。在PHP中使用REST服務的移動應用程序Webservice
我使用下面的鏈接來開發REST服務
http://phpmaster.com/writing-a-restful-web-service-with-slim/
我能夠通過HTML表單添加新的數據,但我想使用的網址添加數據。但我不能。這裏是我使用的代碼
<form action="http://localhost/samples/Restfull/samp5/index.php/custom" method="POST">
<input type="hidden" name="_METHOD" value="POST">
Name: <input type="text" name="Customer_Name"><br>
Mobile: <input type="text" name="Customer_Mobile"><br>
Email: <input type="text" name="Customer_Email"><br>
Address: <textarea name="Customer_Address"></textarea>
<br>
<input type="submit" value="Submit">
</form>
當我嘗試通過這種形式,操作成功完成。但是我想把它作爲Web服務。我嘗試通過url添加數據但失敗,同時使用連接查詢刪除或獲取數據也無效。
我用下面的函數
$app->get("/custom/:id", function ($id) use ($app, $db) {
$app->response()->header("Content-Type", "application/json");
$custom = $db->Registration()->where("Registration_Id", $id);
if ($data = $custom->fetch()) {
echo json_encode(array(
"custom_Name" => $data["Customer_Name"],
"custom_Mobile" => $data["Customer_Mobile"],
"custom_Email" => $data["Customer_Email"],
"custom_Address" => $data["Customer_Address"]
));
}
else{
echo json_encode(array(
"status" => false,
"message" => " $id does not exist"
));
}
});
這也是行之有效的從數據庫取回數據。
是否有其他方式或好樣品可用。不僅在苗條。我需要集成REST服務。請在此建議。
在此先感謝。
你究竟是「我能夠通過形式在HTML中添加新的數據,但我想使用的網址添加數據」是什麼意思?你想開發其餘的服務,它需要url的值? – Ruwantha
S我想開發其餘的服務,它採取值與網址 –