Permalink
Browse files

update attributes

  • Loading branch information...
1 parent c9031bb commit 6f8cf229b4e7501e6b302403d54d993f1ab1fc1b Joshua Stauter committed Apr 15, 2012
Showing with 7 additions and 4 deletions.
  1. +7 −4 index.php
View
@@ -12,13 +12,17 @@ class Todo extends ActiveRecord\Model { }
$app = new Slim();
+function reqBody() {
+ global $app;
+ return json_decode($app->request()->getBody(), true);
+}
+
$app->get('/json', function() {
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 = new Todo(reqBody());
$todo->save();
});
@@ -27,8 +31,7 @@ class Todo extends ActiveRecord\Model { }
});
$app->put('/json/:id', function($id) {
- global $app;
- Todo::find($id)->update_all(array('set' => json_decode($app->request()->getBody(), true)));
+ Todo::find($id)->update_attributes(reqBody());
});
$app->delete('/json/:id', function($id) {

0 comments on commit 6f8cf22

Please sign in to comment.