1

我从https://github.com/ccoenraets/backbone-cellar获得了这段代码,因为我正在尝试学习backbone.js。当我尝试使用 slim.php 向数据库添加新模型时,它显示 500(内部服务器错误)。但是当我试图获取、更新、删除它的工作良好时。为什么它只在添加时显示错误?

请帮助我,谢谢。

    window.WineView = Backbone.View.extend({

        initialize: function () {
            this.render();
        },

        render: function () {
            $(this.el).html(this.template(this.model.toJSON()));
            return this;
        },

        events: {
            "click .save"   : "beforeSave",
            "click .delete" : "deleteWine"

        },

        beforeSave: function () {
            var self = this;
            var check = this.model.validateAll();
            if (check.isValid === false) {
                utils.displayValidationErrors(check.messages);
                return false;
            }

            // Upload picture file if a new file was dropped in the drop area
            if (this.pictureFile) {
                this.model.set("picture", this.pictureFile.name);
                utils.uploadFile(this.pictureFile,
                    function () {
                        self.saveWine();
                    }
                );
            } else {
                this.saveWine();
            }
            return false;
        },

        saveWine: function () {
            var self = this;
            this.model.save(null, {
                success: function (model) {
                    self.render();
                    app.navigate('wines/' + model.id, false);
                    utils.showAlert('Success!', 'Wine saved successfully', 'alert-success');
                },
                error: function () {
                    utils.showAlert('Error', 'An error occurred while trying to add this item', 'alert-error');
                }
            });
        },

        deleteWine: function () {
            this.model.destroy({
                success: function () {
                    alert('Wine deleted successfully');
                    window.history.back();
                }
            });
            return false;
        }

    });
4

1 回答 1

2

我有同样的问题。在您的 /tutorial/api 目录中;打开 index.php 并在函数 addWine() 中查找第一行:

error_log('addWine\n', 3, '/var/tmp/php.log');

评论那一行:

//error_log('addWine\n', 3, '/var/tmp/php.log');

这应该可以解决您的问题,它确实解决了我的问题。

于 2012-07-16T15:58:29.943 回答