|
|
|
@ -8,8 +8,8 @@ |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
class ViewException extends Exception {} |
|
|
|
|
class View { |
|
|
|
|
|
|
|
|
|
class View |
|
|
|
|
{ |
|
|
|
|
private $data; |
|
|
|
|
private $template; |
|
|
|
|
private $layout; |
|
|
|
@ -19,7 +19,8 @@ class View { |
|
|
|
|
* Constructor, init tool path for rendering |
|
|
|
|
* @param string tool name (optional) |
|
|
|
|
*/ |
|
|
|
|
public function __construct($toolname = '', $template_path=null) { |
|
|
|
|
public function __construct($toolname = '', $template_path=null) |
|
|
|
|
{ |
|
|
|
|
if (!empty($toolname)) { |
|
|
|
|
if (isset($template_path)) { |
|
|
|
|
$path = $template_path.$toolname.'/'; |
|
|
|
@ -38,7 +39,8 @@ class View { |
|
|
|
|
* Set data sent from a controller |
|
|
|
|
* @param array data |
|
|
|
|
*/ |
|
|
|
|
public function set_data($data) { |
|
|
|
|
public function set_data($data) |
|
|
|
|
{ |
|
|
|
|
if (!is_array($data)) { |
|
|
|
|
throw new ViewException('View::set_data() $data must to be an array, you have sent a' . gettype( $data )); |
|
|
|
|
} |
|
|
|
@ -49,7 +51,8 @@ class View { |
|
|
|
|
* Set layout view sent from a controller |
|
|
|
|
* @param string layout view |
|
|
|
|
*/ |
|
|
|
|
public function set_layout( $layout ) { |
|
|
|
|
public function set_layout( $layout ) |
|
|
|
|
{ |
|
|
|
|
$this->layout = $layout; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -57,14 +60,16 @@ class View { |
|
|
|
|
* Set template view sent from a controller |
|
|
|
|
* @param string template view |
|
|
|
|
*/ |
|
|
|
|
public function set_template($template) { |
|
|
|
|
public function set_template($template) |
|
|
|
|
{ |
|
|
|
|
$this->template = $template; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Render data to the template and layout views |
|
|
|
|
*/ |
|
|
|
|
public function render() { |
|
|
|
|
public function render() |
|
|
|
|
{ |
|
|
|
|
$content = $this->render_template(); |
|
|
|
|
$target = $this->tool_path.$this->layout.'.php'; |
|
|
|
|
if (file_exists($target)) { |
|
|
|
@ -78,7 +83,8 @@ class View { |
|
|
|
|
* It's used into render method for rendering data in the template and layout views |
|
|
|
|
* @return String Rendered template (as HTML, most of the time) |
|
|
|
|
*/ |
|
|
|
|
private function render_template() { |
|
|
|
|
private function render_template() |
|
|
|
|
{ |
|
|
|
|
$target = $this->tool_path.$this->template.'.php'; |
|
|
|
|
if (file_exists($target)) { |
|
|
|
|
ob_start(); |
|
|
|
@ -91,4 +97,3 @@ class View { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
?> |