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

Namespaces

  • Alo
    • Cache
    • Controller
    • Db
    • Exception
    • Session
    • Statics
    • Test
    • Validators
  • 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       die();
10    }
11 
12    /**
13     * A sample error controller
14     *
15     * @author Art <a.molcanovas@gmail.com>
16     */
17    class SampleErrorController extends AbstractErrorController {
18 
19       /**
20        * Displays the error page
21        *
22        * @author Art <a.molcanovas@gmail.com>
23        * @param int    $code    The error HTTP code
24        * @param string $message Optional message override
25        */
26       function error($code = 404, $message = null) {
27          http_response_code((int)$code);
28          $dir = defined('ENVIRONMENT') && ENVIRONMENT === ENV_SETUP ? DIR_SYS : DIR_APP;
29          $path = $dir . 'error' . DIRECTORY_SEPARATOR . $code . '.html';
30 
31          if (file_exists($path)) {
32             include $path;
33          } else {
34             $this->displayErrorPage($code);
35          }
36       }
37 
38       /**
39        * Displays a generic error page for which there is no HTML file
40        *
41        * @author Art <a.molcanovas@gmail.com>
42        * @param int $code The HTTP response code
43        */
44       function displayErrorPage($code = 404) {
45          $code = (int)$code;
46          echo '<!DOCTYPE html>'
47             . '<html>'
48             . '<head>'
49             . '<title>Uh-oh... ' . $code . '</title>'
50             . '<meta charset="UTF-8">'
51             . '<meta name="viewport" content="width=device-width, initial-scale=1.0">'
52             . '</head>'
53             . '<body>'
54             . '<div>' . $code . ' error page</div>'
55             . '</body>'
56             . '</html>';
57       }
58 
59    }
AloFramework documentation API documentation generated by ApiGen 2.8.0