我想在使用Slim框架的PHP中制作其余的API。如何使用REST API从表中获取数据
我创建了一个功能,让我的表像这样的所有条目: -
<?php
header('Content-type: application/json');
// Include the Slim library
require 'Slim/Slim.php';
// Instantiate the Slim class
$app = new Slim();
// Create a GET-based route
$app->get('/', function() {
echo "Pericent is working on Campus Concierge...";
});
$app->get('/schools', function()
{
$sql = "SELECT * from school";
$result = mysql_query($sql) or die ("Query error: " . mysql_error());
$records = array();
if (mysql_num_rows($result)==0)
{
echo '('.'['.json_encode(array('id' => 0)).']'.')';
}
else
{
while($row = mysql_fetch_assoc($result))
{
$records[] = $row;
}
echo json_encode($records);
}
});
?>
现在我想让它返回学校,id为的详细功能。所以,请建议我怎样才能使一个功能,所以我可以访问学校扣留其ID在URL中给出这样
192.168.1.126/schools/:5