]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | <?php\r |
2 | /**\r | |
3 | * @class Users\r | |
4 | * A simple application controller extension\r | |
5 | */\r | |
6 | class Users extends ApplicationController {\r | |
7 | /**\r | |
8 | * view\r | |
9 | * Retrieves rows from database.\r | |
10 | */\r | |
11 | public function view() {\r | |
12 | $res = new Response();\r | |
13 | $res->success = true;\r | |
14 | $res->message = "Loaded data";\r | |
15 | $res->data = User::all();\r | |
16 | return $res->to_json();\r | |
17 | }\r | |
18 | /**\r | |
19 | * create\r | |
20 | */\r | |
21 | public function create() {\r | |
22 | $res = new Response();\r | |
23 | $rec = User::create($this->params);\r | |
24 | if ($rec) {\r | |
25 | $res->success = true;\r | |
26 | $res->message = "Created new User" . $rec->id;\r | |
27 | $res->data = $rec->to_hash();\r | |
28 | } else {\r | |
29 | $res->message = "Failed to create User";\r | |
30 | }\r | |
31 | return $res->to_json();\r | |
32 | }\r | |
33 | /**\r | |
34 | * update\r | |
35 | */\r | |
36 | public function update() {\r | |
37 | $res = new Response();\r | |
38 | $rec = User::update($this->id, $this->params);\r | |
39 | if ($rec) {\r | |
40 | $res->data = $rec->to_hash();\r | |
41 | $res->success = true;\r | |
42 | $res->message = 'Updated User ' . $this->id;\r | |
43 | } else {\r | |
44 | $res->message = "Failed to find that User";\r | |
45 | }\r | |
46 | return $res->to_json();\r | |
47 | }\r | |
48 | /**\r | |
49 | * destroy\r | |
50 | */\r | |
51 | public function destroy() {\r | |
52 | $res = new Response();\r | |
53 | if (User::destroy($this->id)) {\r | |
54 | $res->success = true;\r | |
55 | $res->message = 'Destroyed User ' . $this->id;\r | |
56 | } else {\r | |
57 | $res->message = "Failed to destroy User";\r | |
58 | }\r | |
59 | return $res->to_json();\r | |
60 | }\r | |
61 | }\r | |
62 | \r |