|
1 |
| -<?php |
2 |
| - |
3 |
| -class View { |
4 |
| - protected $_file; |
5 |
| - protected $_data = array(); |
6 |
| - protected $_withTemplate = true; |
7 |
| - |
8 |
| - |
9 |
| - public $content = ""; |
10 |
| - |
11 |
| - public function __construct($file) { |
12 |
| - $this->_file = $file; |
13 |
| - } |
14 |
| - |
15 |
| - public function set($key, $value) { |
16 |
| - $this->_data[$key] = $value; |
17 |
| - } |
18 |
| - |
19 |
| - public function get($key) { |
20 |
| - return isset($this->_data[$key]) ? $this->_data[$key] : ''; |
21 |
| - } |
22 |
| - |
23 |
| - public function withTemplate($value){ |
24 |
| - $this->_withTemplate = $value; |
25 |
| - } |
26 |
| - |
27 |
| - public function output(){ |
28 |
| - if ($this->_withTemplate){ |
29 |
| - if (!file_exists($this->_file)){ |
30 |
| - throw new Exception("Template " . $this->_file . " doesn't exist."); |
31 |
| - } |
32 |
| - } |
33 |
| - |
34 |
| - extract($this->_data); |
35 |
| - |
36 |
| - ob_start(); |
37 |
| - if ($this->_withTemplate){ |
38 |
| - include($this->_file); |
39 |
| - } |
40 |
| - $this->content = ob_get_contents(); |
41 |
| - ob_end_clean(); |
42 |
| - |
43 |
| - return $this->content; |
44 |
| - } |
45 |
| -} |
| 1 | +<?php |
| 2 | + |
| 3 | +class View { |
| 4 | + protected $_file; |
| 5 | + protected $_data = array(); |
| 6 | + protected $_withTemplate = true; |
| 7 | + |
| 8 | + public $content = ""; |
| 9 | + |
| 10 | + public function __construct($file) { |
| 11 | + $this->_file = $file; |
| 12 | + } |
| 13 | + |
| 14 | + public function set($key, $value) { |
| 15 | + $this->_data[$key] = $value; |
| 16 | + } |
| 17 | + |
| 18 | + public function get($key) { |
| 19 | + return isset($this->_data[$key]) ? $this->_data[$key] : ''; |
| 20 | + } |
| 21 | + |
| 22 | + public function withTemplate($value){ |
| 23 | + $this->_withTemplate = $value; |
| 24 | + } |
| 25 | + |
| 26 | + public function output(){ |
| 27 | + if ($this->_withTemplate){ |
| 28 | + if (!file_exists($this->_file)){ |
| 29 | + throw new Exception("Template " . $this->_file . " doesn't exist."); |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + extract($this->_data); |
| 34 | + |
| 35 | + ob_start(); |
| 36 | + if ($this->_withTemplate){ |
| 37 | + include($this->_file); |
| 38 | + } |
| 39 | + $this->content = ob_get_contents(); |
| 40 | + ob_end_clean(); |
| 41 | + |
| 42 | + return $this->content; |
| 43 | + } |
| 44 | +} |
0 commit comments