2

I have been learning PHP and codeigniter for a year or so now.

However, I am intrigued at what a JS framework can do. I would prefer not to start over in Ruby, though.

I have looked around, but simply can't find enough information on how ember.js or a similar framework works with the backend.

So, assuming I have created a template:

<script type="text/x-handlebars" id="posts">
<div class='posts'>
{{#each model}}
    <h3>{{title}}</h3>
    <p> {{desc}} </p>
{{/each}}
</div>
</script>

and a model

App.Post = DS.Model.extend({
   id: DS.attr('string'),
   title: DS.attr('string'),
   desc: DS.attr('string')
});

How do I get JSON information from a URL? Assuming: http://mypage/ajax/getpostjson/postdata' will return a JSON string with id/title/desc?

The ember.js docs have something like the following:

DS.RESTAdapter.reopen({
  url: 'http://mypage/ajax/getpostjson/postdata'
});

Although I am not sure how you are supposed to call this data or where its stored, or specifically, how youre supposed to use it or set up your app.

In other tutorials, I found this:

App.PostsRoute = Ember.Route.extend({
   model: function() {
       return App.Post.find();
   } 
});

Which I assume connects to App.Post. though I still am very confused.

I am just hoping to get pointed in the right direction through simple examples.

Ricky Mason
  • 1,838
  • 6
  • 31
  • 60
  • 1
    A good point to get started aside from the official ember.js docs and reading trough the source code is http://emberwatch.com/ this answer is maybe also of interest http://stackoverflow.com/questions/14641713/using-embedding-ember-js-with-in-codeigniter – intuitivepixel May 17 '13 at 16:24
  • 1
    "How do I get JSON information from a URL?" - you would create an API (using whatever language, PHP, Ruby, anything...) that matches URL's that ember's data-adapter will request then use your server-side language to access the db and return your objects as JSON. – Anonymous May 20 '13 at 09:14

0 Answers0