Example #1
0
 /**
  * show error page
  *
  * call error action method and set response status code
  * This will work as well for ajax call, see how ajax calls are handled in main.js
  *
  * @param int|string $code
  *
  */
 public function error($code)
 {
     $errors = [404 => "notfound", 401 => "unauthenticated", 403 => "unauthorized", 400 => "badrequest", 500 => "system"];
     if (!isset($errors[$code]) || !method_exists("ErrorsController", $errors[$code])) {
         $code = 500;
     }
     $action = isset($errors[$code]) ? $errors[$code] : "System";
     $this->response->setStatusCode($code);
     // clear, get page, then send headers
     $this->response->clearBuffer();
     (new ErrorsController($this->request, $this->response))->{$action}();
     return $this->response;
 }
Example #2
0
 /**
  * show error page
  *
  * call error action method and set response status code
  * This will work as well for ajax call, see how ajax calls are handled in main.js
  *
  * @param string $error
  *
  */
 public function error($error)
 {
     $errorController = new ErrorsController();
     if (!method_exists("ErrorsController", $error)) {
         $error = "System";
     }
     $errors = ["notfound" => 404, "system" => 500, "badrequest" => 400, "unauthorized" => 401, "forbidden" => 403];
     $code = isset($errors[strtolower($error)]) ? $errors[strtolower($error)] : 500;
     $this->response->setStatusCode($code);
     //clear, get page, then send headers
     $this->response->clearBuffer();
     $errorController->{$error}();
     $this->response->send();
 }