Skip to content

Commit

Permalink
works
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Stauter committed Apr 15, 2012
1 parent 072c088 commit a634e3d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
2 changes: 2 additions & 0 deletions README.md
@@ -0,0 +1,2 @@
This is the classic [Backbone Todos app](http://addyosmani.github.com/todomvc),
backended by a JSON API in PHP.
6 changes: 2 additions & 4 deletions index.html
Expand Up @@ -21,7 +21,7 @@ <h1>Todos</h1>

<div id="create-todo">
<input id="new-todo" placeholder="What needs to be done?" type="text">
<span class="ui-tooltip-top" style="display:none;">Press Enter to save this task</span>
<span class="ui-tooltip-top" style="display:none">Press Enter to save this task</span>
</div>

<div id="todos">
Expand All @@ -39,9 +39,7 @@ <h1>Todos</h1>
<div id="credits">
Tip o' the hat to:<br>
<a href="http://jgn.me">J&eacute;r&ocirc;me Gravel-Niquet</a>,
<a href="http://addyosmani.com">Addy Osmani</a>,
<a href="http://ashkenas.com">Jeremy Ashkenas</a>,
<a href="http://tinyclouds.org">Ryan Dahl</a>,<br>
<a href="http://addyosmani.com">Addy Osmani</a>,<br>
and everyone else that powers the tubes.
</div>

Expand Down
20 changes: 16 additions & 4 deletions index.php
Expand Up @@ -5,21 +5,33 @@
class Todo extends ActiveRecord\Model { }

ActiveRecord\Config::initialize(function($cfg) {
$cfg->set_model_directory('.');
$cfg->set_connections(array('development' => 'mysql://root:@localhost/todos'));
});


$app = new Slim();

$app->get('/json', function() {
echo "Index";
echo json_encode(array_map(function($todo) { return $todo->attributes(); }, Todo::all()));
});

$app->post('/json', function() {
global $app;
$todo = new Todo(json_decode($app->request()->getBody(), true));
$todo->save();
});

$app->get('/json/:id', function($id) {
echo "Hello, $id!";
echo Todo::find($id)->to_json();
});

$app->put('/json/:id', function($id) {
global $app;
Todo::find($id)->update_all(array('set' => json_decode($app->request()->getBody(), true)));
});
$app->post('/json', function() {

$app->delete('/json/:id', function($id) {
Todo::find($id)->delete();
});

$app->run();
4 changes: 2 additions & 2 deletions todos.js
Expand Up @@ -40,10 +40,10 @@ $(function(){
// Todo Collection
// ---------------

// The collection of todos is backed by a remote server.
// The collection of todos is backed by a web service.
var TodoList = Backbone.Collection.extend({

url: '/todos',
url: '/json',

// Reference to this collection's model.
model: Todo,
Expand Down
4 changes: 2 additions & 2 deletions todos.sql
@@ -1,6 +1,6 @@
create table todos(
id int not null primary key auto_increment,
content varchar(50),
done varchar(50),
order varchar(50)
done tinyint(1),
order int
);

0 comments on commit a634e3d

Please sign in to comment.