forked from xw2423/nForum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview.php
93 lines (74 loc) · 2.12 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
class NF_View implements Yaf_View_Interface{
private static $_views = array();
protected $_vars = array();
protected $_request = null;
protected $_initHeader = false;
public static function getInstance($request){
$ext = $request->ext;
if(isset(self::$_views[$ext]))
return self::$_views[$ext];
if(!load("inc/views/{$ext}"))
exit();
$class = ucfirst($ext) . 'View';
if(!class_exists($class))
exit();
if(!is_subclass_of($class, __CLASS__))
exit();
return (self::$_views[$ext] = new $class($request));
}
public function __construct($request){
$this->_request = $request;
}
public function render($tpl, $tpl_vars = array()){
return '';
}
public function display($tpl, $tpl_vars = null){
echo $this->render($tpl, $tpl_vars);
}
public function assign($name, $value = null){
return $this->set($name, $value);
}
/**
* assing variable to templete
* @param $one string or array
* @param $two mixed
*/
public function set($one, $two = null) {
if(is_array($one) && is_null($two)){
foreach($one as $k => $v){
$this->_vars[$k] = $v;
}
}
if(is_string($one) && !is_null($two)){
$this->_vars[$one] = $two;
}
}
/**
* get variable of templete
* @param $name string
* @return value|null
*/
public function get($name = null) {
return isset($this->_vars[$name])?$this->_vars[$name]:null;
}
public function clear($one){
if(is_array($one)){
foreach($one as $k => $v){
unset($this->_vars[$k]);
}
}
if(is_string($one)){
unset($this->_vars[$one]);
}
}
public function clearAll(){
$this->_vars = array();
}
public function getScriptPath(){ return '';}
public function setScriptPath($dir){}
protected function _initHeader(){
if($this->_initHeader) return;
$this->_initHeader = true;
}
}