forked from tilgo/ep-store
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewHelper.php
More file actions
63 lines (46 loc) · 1.84 KB
/
Copy pathViewHelper.php
File metadata and controls
63 lines (46 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
class ViewHelper {
public static function render($file, $variables = array ()) {
extract($variables);
ob_start();
include($file);
return ob_get_clean();
}
public static function renderJSON($data, $httpResponseCode = 200) {
header('Content-Type: application/json');
http_response_code($httpResponseCode);
return json_encode($data);
}
public static function redirect($url) {
header("Location: " . $url);
}
// Displays a simple 404 message
public static function error404() {
header('This is not the page you are looking for', true, 404);
$html404 = sprintf("<!doctype html>\n" .
"<title>Error 404: Page does not exist</title>\n" .
"<h1>Error 404: Page does not exist</h1>\n" .
"<p>The page <i>%s</i> does not exist.</p>", $_SERVER["REQUEST_URI"]);
echo $html404;
}
public static function displayError($exception, $debug = false) {
header('An error occurred.', true, 400);
if ($debug) {
$hmtl = sprintf("<!doctype html>\n" .
"<title>Error: An application error.</title>\n" .
"<h1>Error: An application error</h1>\n" .
"<p>The page <i>%s</i> returned an error:" .
"<blockquote><pre>%s</pre></blockquote></p>", $_SERVER["REQUEST_URI"], $exception);
} else {
$hmtl = sprintf("<!doctype html>\n" .
"<title>Error: An application error.</title>\n" .
"<h1>Error: An application error</h1>\n" .
"<p>The page <i>%s</i> returned an error.", $_SERVER["REQUEST_URI"]);
}
echo $hmtl;
}
}
class ResponseType {
const HTML = 0;
const JSON = 1;
}