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