4 * A simple application controller extension
6 class Users extends ApplicationController {
9 * Retrieves rows from database.
11 public function view() {
12 $res = new Response();
14 $res->message = "Loaded data";
15 $res->data = User::all();
16 return $res->to_json();
21 public function create() {
22 $res = new Response();
23 $rec = User::create($this->params);
26 $res->message = "Created new User" . $rec->id;
27 $res->data = $rec->to_hash();
29 $res->message = "Failed to create User";
31 return $res->to_json();
36 public function update() {
37 $res = new Response();
38 $rec = User::update($this->id, $this->params);
40 $res->data = $rec->to_hash();
42 $res->message = 'Updated User ' . $this->id;
44 $res->message = "Failed to find that User";
46 return $res->to_json();
51 public function destroy() {
52 $res = new Response();
53 if (User::destroy($this->id)) {
55 $res->message = 'Destroyed User ' . $this->id;
57 $res->message = "Failed to destroy User";
59 return $res->to_json();