Created
May 30, 2012 00:55
-
-
Save anonymous/2831912 to your computer and use it in GitHub Desktop.
Start of Hybrid Controller for syncing FuelPHP with Backbone.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Controller_Todos extends Controller_Hybrid | |
{ | |
public function action_index() | |
{ | |
$data['todos'] = Model_Todo::find('all'); | |
$this->template->title = "Todos"; | |
$this->template->content = View::forge('todos/index', $data); | |
} | |
public function get_index() | |
{ | |
if(Input::get('id')) | |
{ | |
$id = Input::get('id'); | |
$todo = Model_Todo::find($id); | |
$this->response($todo); | |
} | |
else | |
{ | |
$todos = Model_Todo::find('all'); | |
$this->response($todos); | |
} | |
} | |
public function post_index() | |
{ | |
$val = Model_Todo::validate('create'); | |
if ($val->run(Input::json())) | |
{ | |
$todo = Model_Todo::forge(array( | |
'title' => Input::json('title'), | |
'description' => Input::json('description'), | |
'completed' => Input::json('completed'), | |
)); | |
if ($todo and $todo->save()) | |
{ | |
$this->response($todo); | |
} | |
else | |
{ | |
$this->response(array( | |
'error' => true, | |
)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good example!