我必须在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我想开发其余的服务,它采取值与网址 –