I'm tring to write my first Backbone.js app
inside my CakePHP app
and trying to avoid writing my app in the page directly but to do it on a specific file stored in js/backbone/app.js
where I'll put the Backbone app.
My first test was made by writing the app inside the page just to make some test, the problem is that the Model app has default values which came from php data.
Here is the example without including the app.js
:
<html>
<head>
<title>My app test</title>
<script type="text/javascript" src="js/backbone/backbone.min.js"></script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/underscore.min.js"></script>
<script type="text/javascript">
var Status = {
Models: {},
Collections: {},
Views: {},
Templates:{}
}
Status.Models.Message = Backbone.Model.extend({
defaults:{
icon:"<?php echo $this->App->icon('default-icon-name');?>",
type:"warning",
title:"<?php echo __('Default title'); ?>",
message:"<?php echo __('Default status message text'); ?>"
},
initialize:function () {
console.log("Backbone console message from initialize event");
}
});
// here the rest of the app
</script>
</head>
<body>
here is the app!
</body>
</html>
Now I've moved the app inside js/backbone/app.js
and I'm not sure how is the easiest way to pass the default parameters of the Model from the page inside my app.js
.
Here is the example where I've put all the Backbone app inside the app.js
:
$(function(){
$.ajax({
url: "http://site.com/json/default_app"
}).done(function(data) {
var Status = {
Models: {},
Collections: {},
Views: {},
Templates:{}
}
Status.Models.Message = Backbone.Model.extend({
defaults:data,
initialize:function () {
console.log("Backbone console message from initialize event");
}
});
});
})(jQuery);
Should i put my app for example inside the document ready of jQuery
? I hope not, this would force me to create a specific Controller
inside my CakePHP
app that would be very annoying to keep up to date.