-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path_helper.php
52 lines (39 loc) · 1.04 KB
/
_helper.php
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
<?php
function dd($data) {
header('Content-type: application/json');
echo json_encode($data);
die();
}
function get($key) {
if (isset($_GET[$key])) return trim($_GET[$key]);
return "";
}
function post($key) {
if (isset($_POST[$key])) {
return trim($_POST[$key]);
}
return "";
}
function redirect($location) {
header("location: $location");
die();
}
function flashMessage($name, $message, $type) {
// remove existing message with the name
if (isset($_SESSION[FLASH][$name])) {
unset($_SESSION[FLASH][$name]);
}
$_SESSION[FLASH][$name] = ['message' => $message, 'type' => $type];
}
function formattedFlashMessage($flashMessage) {
return sprintf("<div class='alert alert-%s'>%s</div>",
$flashMessage['type'],
$flashMessage['message']
);
}
function displayFlashMessage($name) {
if (!isset($_SESSION[FLASH][$name])) return;
$flashMessage = $_SESSION[FLASH][$name];
unset($_SESSION[FLASH][$name]);
echo formattedFlashMessage($flashMessage);
}