视图值更改后如何更新MySQL数据库

时间:2018-11-05 16:07:33

标签: php mysql angularjs codeigniter

我得到了这个用Codeigniter / AngularJs编写的体育网站项目,而我被困在视图/控制器/模型之间的通信上。

有此功能可以更新用户观点,然后我也应该使用此dataSavingHttp服务来更新数据库,但是我对其功能确实感到困惑

View Angularjs控制器

$scope.buy_salary_cap = function() {
    $scope.remainSalary = parseInt($scope.contestDetails.salary_cap/10) + parseInt($scope.remainSalary);
    $rootScope.profile_data.points_balance = parseInt($rootScope.profile_data.points_balance) + parseInt(1);

    dataSavingHttp({
        url: site_url+"lineup/update_user_points_balance",
        data: {},
    }).success(function (response) {
        $scope.content = response.data.points_balance;
    }).error(function (error) {
        $scope.content = "Erro!";
    });


    $scope.isDisabled = true;
}

Codeigniter控制器

   private function update_user_points_balance()
{
    return $this->Lineup_model->update_user_points_balance();
}

模型功能

    public function update_user_points_balance()
{
    $condition = array('user_id' => $this->session->userdata('user_id'));
    $config['points_balance'] = $this->remain_balance;
    $this->table_name = USER;
    return $this->update($condition , $config);
}

这是dataSavingHttp代码

vfantasy.factory('dataSavingHttp', function($http, $location) {
var wrapper = function(requestConfig) {
    var options = angular.extend({
        url: "",
        method: "POST",
        data : '',
        dataType: "json",
    },requestConfig);

    var httpPromise = $http(options);

    httpPromise.success(function(result, status, headers, config){
        var l = window.location;
        wrapper.lastApiCallConfig = config;
        wrapper.lastApiCallUri = l.protocol + '//' + l.host + '' + config.url + '?' +
            (function(params){
                var pairs = [];
                angular.forEach(params, function(val, key){
                    pairs.push(encodeURIComponent(key)+'='+encodeURIComponent(val));
                });
                return pairs.join('&')
            })(config.params);
        wrapper.lastApiCallResult = result;
    })
    return httpPromise;
};
return wrapper;
});

也许有一个更简单的解决方案,但是我真的是这些语言的新手。预先感谢。

0 个答案:

没有答案