source: trunk/web/addons/job_monarch/lib/extjs-30/examples/restful/remote/app/controllers/users.php @ 625

Last change on this file since 625 was 625, checked in by ramonb, 15 years ago

lib/extjs-30:

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