Skip to content

Instantly share code, notes, and snippets.

Created May 30, 2012 00:55
Show Gist options
  • Save anonymous/2831912 to your computer and use it in GitHub Desktop.
Save anonymous/2831912 to your computer and use it in GitHub Desktop.
Start of Hybrid Controller for syncing FuelPHP with Backbone.js
<?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,
));
}
}
}
@GregoryCollett
Copy link

Good example!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment