-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview.php
78 lines (67 loc) · 1.65 KB
/
view.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
include_once('iview.php');
class View implements IView
{
public $modes = array(
'html' => 'html',
'text' => 'html',
'tpl' => 'tpl',
'js' => 'js',
'json' => 'json',
'result' => 'result',
'debug' => 'debug'
);
public function html($result)
{
Header("content-type: text/html; charset=utf-8");
echo $result;
}
public function tpl($result)
{
require('../smarty/smarty.class.php');
$smarty = new Smarty();
$smarty->setTemplateDir('../smarty/templates');
$smarty->setCompileDir('../smarty/templates_c');
$smarty->setCacheDir('../smarty/cache');
$smarty->setConfigDir('../smarty/configs');
$smarty->assign('data', $result['data']);
Header("content-type: text/html; charset=utf-8");
echo $smarty->fetch($result['tpl']);
}
public function debug($result)
{
Header("content-type: text/html; charset=utf-8");
print_r($result);
}
public function json($result)
{
Header("content-type: application/json; charset=utf-8");
return json_encode($result);
}
public function js($result)
{
Header("content-type: application/javascript; charset=utf-8");
echo $result;
}
public function result($result)
{
$json = $result === true ? array('result' => true) : array('result' => false);
return $this->json($json);
}
public function output($result, $mode, $callback = null)
{
if (isset($callback) && ($mode != 'json' || $mode != 'result')) {
$mode = 'json';
}
$raw = '';
if (array_key_exists($mode, $this->modes)) {
$methodName = $this->modes[$mode];
$raw = $this->$methodName($result, null);
}
if (isset($callback)){
echo $callback . '(' . $raw . ')';
}else if (isset($raw)){
echo $raw;
}
}
}