コード例 #1
0
ファイル: WebApp.php プロジェクト: telander/waka
 private function route($controllerName, $actionName)
 {
     $controllerClass = ucfirst($controllerName . 'Controller');
     if (class_exists($controllerClass)) {
         /** @var K_Controller $runC */
         $runC = new $controllerClass($actionName);
         $this->controller = $runC;
         $runC->run($actionName);
     } else {
         if (Wk_Request::isAjax()) {
         } else {
             Wk_Request::redirect('/');
         }
     }
     $this->stop();
 }
コード例 #2
0
ファイル: Wk_WebController.php プロジェクト: telander/waka
 /**
  * 返回错误信息
  *
  * @param  string $errorMsg
  * @param  int $errorCode
  * @param  int $httpStatus
  */
 public function returnError($errorMsg = '', $errorCode = -1, $httpStatus = 200)
 {
     if ($httpStatus !== 200) {
         switch ($httpStatus) {
             case 404:
                 header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
                 echo '404 Not Found';
                 break;
             case 403:
                 header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden');
                 echo '403 Forbidden';
                 break;
             case 500:
                 header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error');
                 echo '500 Internal Server Error';
                 break;
             default:
                 header($_SERVER['SERVER_PROTOCOL'] . ' ' . $httpStatus . ' Http Error');
                 echo $httpStatus . ' Http Error';
                 break;
         }
     } elseif (Wk_Request::isAjax()) {
         header('Content-Type: application/json; charset=utf-8');
         if (!empty($errorMsg)) {
             echo json_encode(['ok' => 0, 'msg' => $errorMsg, 'code' => $errorCode], JSON_UNESCAPED_UNICODE);
         } else {
             echo json_encode(['ok' => 0, 'msg' => TErrorConstants::getErrorMsg($errorCode), 'code' => $errorCode], JSON_UNESCAPED_UNICODE);
         }
     } else {
         if (empty($errorMsg)) {
             $errorMsg = TErrorConstants::getErrorMsg($errorCode);
         }
         Wk::logger()->err('page error:' . $errorCode . (empty($errorMsg) ? '' : '(' . $errorMsg . ')'));
         // $this->renderView('/layouts/404');
         echo 'error: ' . $errorCode . (empty($errorMsg) ? '' : '(' . $errorMsg . ')');
     }
     Wk::app()->stop();
 }