application_controller.php
上传用户:dawnssy
上传日期:2022-08-06
资源大小:9345k
文件大小:1k
源码类别:

JavaScript

开发平台:

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.         // normal dispatch here.  discover action
  22.     }
  23.     protected function dispatchRestful() {
  24.         switch ($this->request->method) {
  25.             case 'GET':
  26.                 return $this->view();
  27.                 break;
  28.             case 'POST':
  29.                 return $this->create();
  30.                 break;
  31.             case 'PUT':
  32.                 return $this->update();
  33.                 break;
  34.             case 'DELETE':
  35.                 return $this->destroy();
  36.                 break;
  37.         }
  38.     }
  39. }