-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.class.php
64 lines (52 loc) · 1.13 KB
/
controller.class.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
53
54
55
56
57
58
59
60
61
62
63
64
<?php
class Controller
{
protected $msg = array();
protected function view($viewName)
{
return new View($viewName);
}
protected function model($modelName)
{
require_once(ROOT . "/app/models/" . $modelName . ".model.php");
$model = new $modelName();
return $model;
}
protected function template($viewName, $data = array())
{
$view = $this->view('template');
$view->bind('viewName', $viewName);
$view->bind('data', $data);
return $view;
}
public function back()
{
echo "
<script>
history.go(-1)
</script>
";
}
public function redirect($url = "")
{
header('location: ' . BASE_PATH . DS . $url);
}
public function redirectData($url = "", $data = array())
{
// Simpan data di sesi
foreach ($data as $key => $value) {
$_SESSION[$key] = $value;
}
// Lakukan redirect
header('location: ' . BASE_PATH . $url);
exit();
}
public function sendData($viewName, $data = array())
{
$this->template($viewName, $data)->render();
}
protected function validate($data)
{
return htmlentities(trim(strip_tags($data)));
}
}