-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.php
More file actions
124 lines (103 loc) · 2.13 KB
/
helpers.php
File metadata and controls
124 lines (103 loc) · 2.13 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
/**
* Get the base path
* @param string $path
* @return string
*/
function basePath($path = ''){
return __DIR__ . '/' . $path;
}
/**
* Load a view
* @param string $name
* @return void
*/
function loadView($name){
$viewPath = basePath("app/views/{$name}.php");
if (file_exists($viewPath)) {
require $viewPath;
} else {
echo "view '{$name} not found!'";
}
}
/**
* Load a model
* @param string $name
* @return void
*/
function loadModel($name){
$modelPath = basePath("app/models/{$name}.php");
if (file_exists($modelPath)) {
require $modelPath;
} else {
echo "model '{$name} not found!'";
}
}
/**
* Load a database
* @param string $name
* @return void
*/
function loadDB($name){
$dbPath = basePath("app/models/DB/{$name}.php");
if (file_exists($dbPath)) {
require $dbPath;
} else {
echo "model '{$name} not found!'";
}
}
/**
* Load a controller
* @param string $name
* @return void
*/
function loadController($name){
$conPath = basePath("app/controllers/{$name}.php");
if (file_exists($conPath)) {
require $conPath;
} else {
echo "controller '{$name} not found!'";
}
}
/**
* Count a number
* @param array $name
* @return array
*/
function countNum($name){
$count = 0;
foreach ($name as $value) {
if (is_array($value)) {
$count += countNum($value);
}else{
$count++;
}
}
return $count;
}
/**
*
* Format a Count
* @param int $name
* @return int
*/
function formatNum($name){
if ($name < 1000) {
return $name;
}elseif ($name < 1000000) {
return number_format($name / 1000, 1) . 'K';
}elseif ($name < 1000000000) {
return number_format($name / 1000000, 1) . 'M';
}else{
return number_format($name / 1000000000, 1) . 'B';
}
}
/**
* @param string $data
* @return mixed
*/
function jsonResponse($data) {
// header('Content-Type: application/json');
echo json_encode($data);
// exit(); // Make sure to exit to prevent further execution
}