我正在制作一个 Angular 应用程序,对于后端,我使用 symphony 的微框架创建一个 REST API:silex。
在某个更新中,我不断收到内部服务器错误。我所做的就是更新权重。
$app->put('/{id}/updateWeight', function ($id) use ($app) {
$sql = "UPDATE results SET weight=20 WHERE usersId = $id";
$test = $app['db']->executeUpdate($sql, array((int) $id));
return $test;
});
最佳答案
感谢大家的回复,在我想发布错误之前,我又仔细查看了错误,发现了问题。
我认为错误是在我上面发布的代码段中创建的,但实际上这条路线似乎与另一条路线混淆了,即这条路线:
$app->put('/{name}/{goalsId}', function ($name, $goalsId) use ($app) {
$sql = "UPDATE users SET goalsId=".$goalsId." WHERE username ='".$name."' ";
$users = $app['db']->executeUpdate($sql, array($goalsId, (int) $name));
//$user = $app['db']->fetchAssoc($sql, array((string) $username));
return $goalsId;
});
这显然造成了错误。
更改路线
$http.put("../api/web/"+user.usersId+"/updateWeight/")
至
$http.put("../api/web/updateweight/"+user.usersId)
成功了。
关于php - 使用 php 框架 silex 更新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30264430/