我在这里遇到错误,因为我尝试使用slim作为API更新数据,并将角度更改为客户端。
我的苗条码:
<?php
$app->put("/update/:id",function($id)use($app){
$body = $app->request->getBody();
$user = json_decode($body);
$newData = Users::find($id);
$newData->username = $user->username;
$newData->first_name = $user->first_name;
$newData->last_name = $user->last_name;
$newData->address = $user->address;
echo $newData->save();
});
我的更新角度代码:
app.controller('editUserController',function($scope, $http, $location, $routeParams){
var id = $routeParams.id;
$http.get('http://address.com/slimApi/index.php/cekOne/'+ id).success(function(response){
$scope.users = response;
});
$scope.updateUser = function()
{
var r = confirm('Are you sure??');
if (r==true) {
$http.put('http://address.com/slimApi/index.php/update/' + id, $scope.users).success(function(response){
$scope.users = '';
$location.path('/');
});
} else{};
}
});