Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / examples / restful / remote / app / controllers / users.php
diff --git a/examples/restful/remote/app/controllers/users.php b/examples/restful/remote/app/controllers/users.php
new file mode 100644 (file)
index 0000000..7085106
--- /dev/null
@@ -0,0 +1,62 @@
+<?php
+/**
+ * @class Users
+ * A simple application controller extension
+ */
+class Users extends ApplicationController {
+    /**
+     * view
+     * Retrieves rows from database.
+     */
+    public function view() {
+        $res = new Response();
+        $res->success = true;
+        $res->message = "Loaded data";
+        $res->data = User::all();
+        return $res->to_json();
+    }
+    /**
+     * create
+     */
+    public function create() {
+        $res = new Response();
+        $rec = User::create($this->params);
+        if ($rec) {
+            $res->success = true;
+            $res->message = "Created new User" . $rec->id;
+            $res->data = $rec->to_hash();
+        } else {
+            $res->message = "Failed to create User";
+        }
+        return $res->to_json();
+    }
+    /**
+     * update
+     */
+    public function update() {
+        $res = new Response();
+        $rec = User::update($this->id, $this->params);
+        if ($rec) {
+            $res->data = $rec->to_hash();
+            $res->success = true;
+            $res->message = 'Updated User ' . $this->id;
+        } else {
+            $res->message = "Failed to find that User";
+        }
+        return $res->to_json();
+    }
+    /**
+     * destroy
+     */
+    public function destroy() {
+        $res = new Response();
+        if (User::destroy($this->id)) {
+            $res->success = true;
+            $res->message = 'Destroyed User ' . $this->id;
+        } else {
+            $res->message = "Failed to destroy User";
+        }
+        return $res->to_json();
+    }
+}
+