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 14 15 16
17 class SampleErrorController extends AbstractErrorController {
18
19 20 21 22 23 24 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 40 41 42 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 }