Upgrade to ExtJS 3.2.0 - Released 03/30/2010
[extjs.git] / examples / restful / remote / lib / application_controller.php
1 <?php
2 /**
3  * @class ApplicationController
4  */
5 class ApplicationController {
6     public $request, $id, $params;
7
8     /**
9      * dispatch
10      * Dispatch request to appropriate controller-action by convention according to the HTTP method.
11      */
12     public function dispatch($request) {
13         $this->request = $request;
14         $this->id = $request->id;
15         $this->params = $request->params;
16
17         if ($request->isRestful()) {
18             return $this->dispatchRestful();
19         }
20         if ($request->action) {
21             return $this->{$request->action}();
22         }
23     }
24
25     protected function dispatchRestful() {
26         switch ($this->request->method) {
27             case 'GET':
28                 return $this->view();
29                 break;
30             case 'POST':
31                 return $this->create();
32                 break;
33             case 'PUT':
34                 return $this->update();
35                 break;
36             case 'DELETE':
37                 return $this->destroy();
38                 break;
39         }
40     }
41 }
42