AloFramework documentation
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo

Namespaces

  • Alo
    • Cache
    • CLI
    • Controller
    • Db
      • Query
    • Exception
    • FileSystem
    • Session
    • Traversables
    • Validators
    • Windows
  • Controller
  • None
  • PHP

Classes

  • Cart
  • Sample
  • SampleErrorController
 1 <?php
 2 
 3     namespace Controller;
 4 
 5     use Alo\Controller\AbstractErrorController;
 6 
 7     if (!defined('GEN_START')) {
 8         http_response_code(404);
 9     } else {
10 
11         /**
12          * A sample error controller
13          *
14          * @author Art <a.molcanovas@gmail.com>
15          */
16         class SampleErrorController extends AbstractErrorController {
17 
18             /**
19              * Displays the error page
20              *
21              * @author Art <a.molcanovas@gmail.com>
22              *
23              * @param int $code The error HTTP code
24              */
25             function error($code = 404) {
26                 http_response_code((int)$code);
27                 $dir  = defined('ENVIRONMENT') && ENVIRONMENT === ENV_SETUP ? DIR_SYS : DIR_APP;
28                 $path = $dir . 'error' . DIRECTORY_SEPARATOR . $code . '.html';
29 
30                 if (file_exists($path)) {
31                     include $path;
32                 } else {
33                     $this->displayErrorPage($code);
34                 }
35             }
36 
37             /**
38              * Displays a generic error page for which there is no HTML file
39              *
40              * @author Art <a.molcanovas@gmail.com>
41              *
42              * @param int $code The HTTP response code
43              */
44             function displayErrorPage($code = 404) {
45                 $code = (int)$code;
46                 echo '<!DOCTYPE html>' . '<html>' . '<head>' . '<title>Uh-oh... ' . $code . '</title>' .
47                      '<meta charset="UTF-8">' .
48                      '<meta name="viewport" content="width=device-width, initial-scale=1.0">' . '</head>' . '<body>' .
49                      '<div>' . $code . ' error page</div>' . '</body>' . '</html>';
50             }
51 
52         }
53     }
54 
AloFramework documentation API documentation generated byApiGen 2.8.0