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