Example #1
0
 /**
  * Displays a 404 Page Not Found error. If set, will try to
  * call the 404Override controller/method that was set in routing config.
  *
  * @param PageNotFoundException $e
  */
 protected function display404errors(PageNotFoundException $e)
 {
     // Is there a 404 Override available?
     if ($override = $this->router->get404Override()) {
         if ($override instanceof \Closure) {
             echo $override();
         } else {
             if (is_array($override)) {
                 $this->benchmark->start('controller');
                 $this->benchmark->start('controller_constructor');
                 $this->controller = $override[0];
                 $this->method = $override[1];
                 unset($override);
                 $controller = $this->createController();
                 $this->runController($controller);
             }
         }
         $this->gatherOutput();
         $this->sendResponse();
         return;
     }
     // Display 404 Errors
     $this->response->setStatusCode(404);
     if (ENVIRONMENT !== 'testing') {
         if (ob_get_level() > 0) {
             ob_end_flush();
         }
     } else {
         // When testing, one is for phpunit, another is for test case.
         if (ob_get_level() > 2) {
             ob_end_flush();
         }
     }
     ob_start();
     // These might show as unused here - but don't delete!
     // They are used within the view files.
     $heading = 'Page Not Found';
     $message = $e->getMessage();
     // Show the 404 error page
     if (is_cli()) {
         require APPPATH . 'Views/errors/cli/error_404.php';
     } else {
         require APPPATH . 'Views/errors/html/error_404.php';
     }
     $buffer = ob_get_contents();
     ob_end_clean();
     echo $buffer;
     $this->callExit(EXIT_UNKNOWN_FILE);
     // Unknown file
 }