03.12.2015 Views

laravel4cookbook

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Real Time Chat 175<br />

18 App.ApplicationAdapter = DS.FixtureAdapter.extend();<br />

19<br />

20 // 5<br />

21 App.Message.FIXTURES = [<br />

22 {<br />

23 "id" : 1,<br />

24 "user" : "Chris",<br />

25 "text" : "Hello World."<br />

26 },<br />

27 {<br />

28 "id" : 2,<br />

29 "user" : "Wayne",<br />

30 "text" : "Don't dig it, man."<br />

31 },<br />

32 {<br />

33 "id" : 3,<br />

34 "user" : "Chris",<br />

35 "text" : "Meh."<br />

36 }<br />

37 ];<br />

.<br />

This file should be saved as public/js/shared.js.<br />

If you’re an EmberJS noob, like me, then it will help to understand what each piece of this script is<br />

doing.<br />

1. We create a new Ember application with Ember.Application.create().<br />

2. Routes are defined in the App.Route.map() method, and we tell the application to equate the<br />

path / to the index resource.<br />

3. We define a Message model. These are similar to the Eloquent models we have in Laravel 4,<br />

but they’re built to work with EmberJS (and are obviously on the client-side of the application).<br />

4. We specify a fixture-based data store for our application. We’re using this, temporarily, to fill<br />

our interface with some dummy data, but we’ll add a dynamic data store before too long…<br />

5. Here we add the fixture data. Notice that, in addition to the two model fields we defined, we<br />

also specify ID values for the fixture rows. This data is used to single out individual Message<br />

objects.<br />

When you browse to the base URL of the application; you should now see an acceptably styled list<br />

of message objects, along with a heading and input form. Let’s make it dynamic!

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!