Reputation: 3
I try to run basic CRUD operations with backbone js and PHP REFTful service.
Then my web service works fine but i have trouble with backbone sync when i want delete there is no JSON send to my web service but with add,update i have that JSON.
So i cant't delete with my web service, maybe i have the bad method to do that.
That is the code :
app.js
$(function(){
//MODELES
window.Article = Backbone.Model.extend({
defaults : {
id : null,
titre : null,
contenu : null,
image : null
},
initialize : function Doc() {
console.log('Article Constructor');
this.url = "index.php/article/article/id/"+this.id,
this.bind("error", function(model, error){
console.log( error );
});
},
validate: function( attributes ){
if( attributes.titre === '') {
return "Titre ne peut pas être vide ";
}
}
});
//COLLECTIONS
window.Articles = Backbone.Collection.extend({
model : Article,
url : "index.php/article",
initialize : function() {
console.log('Articles collection Constructor');
}
});
});
index.php
<!DOCTYPE HTML PUBLIC>
<html>
<head>
<title>Main Page</title>
<script src="<?php echo base_url(); ?>js/vendor/jquery-1.10.1.min.js"></script>
<script src="<?php echo base_url(); ?>js/vendor/underscore-min.js"></script>
<script src="<?php echo base_url(); ?>js/vendor/backbone-min.js"></script>
<script src="<?php echo base_url(); ?>js/app.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
</body>
</html>
I'm doing my test in the chromium console.
listArticles = new Articles();
unArticle = new Article();
unArticle.set('titre','Le titre');
listArticles.add(unArticle);
unArticle.save(); //THAT WORKS
unArticle.destroy(); //DONT WORKS (SEND THE REQUEST BUT WITHOUT THE JSON, WITHOUT GET ID)
thanks in advance
Upvotes: 0
Views: 137
Reputation: 816
Try this : Backbonejs with Restful servcies
it is a good example about Backbonejs and restful services.
Upvotes: 1