application_controller.php
上传用户:shuoshiled
上传日期:2018-01-28
资源大小:10124k
文件大小:1k
源码类别:

中间件编程

开发平台:

JavaScript

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