| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* A Singleton class for loading view template |
| 5 |
*/ |
| 6 |
class VP_View |
| 7 |
{ |
| 8 |
|
| 9 |
/** |
| 10 |
* Singleton instance of the class |
| 11 |
* @var Option_View |
| 12 |
*/ |
| 13 |
private static $_instance; |
| 14 |
|
| 15 |
private $_views; |
| 16 |
|
| 17 |
private function __construct() |
| 18 |
{ |
| 19 |
$this->_views = array(); |
| 20 |
} |
| 21 |
|
| 22 |
public static function instance() |
| 23 |
{ |
| 24 |
if (is_null(self::$_instance)) |
| 25 |
{ |
| 26 |
self::$_instance = new self(); |
| 27 |
} |
| 28 |
return self::$_instance; |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Load view file |
| 33 |
* @param String $field_view_file Name of the view file |
| 34 |
* @param Array $data Array of data to be binded on the view |
| 35 |
* @return String The result view |
| 36 |
*/ |
| 37 |
public function load($field_view_file, $data = array()) |
| 38 |
{ |
| 39 |
if (array_key_exists('field_view_file', $data)) |
| 40 |
{ |
| 41 |
throw new Exception("Sorry 'field_view_file' variable name can't be used."); |
| 42 |
} |
| 43 |
|
| 44 |
$view_file = VP_FileSystem::instance()->resolve_path('views', $field_view_file); |
| 45 |
|
| 46 |
if($view_file === false) |
| 47 |
{ |
| 48 |
throw new Exception("View file not found."); |
| 49 |
} |
| 50 |
|
| 51 |
extract($data); |
| 52 |
ob_start(); |
| 53 |
include $view_file; |
| 54 |
return ob_get_clean(); |
| 55 |
} |
| 56 |
|
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* EOF |
| 61 |
*/ |