the view class
<?php
class View {
private $template;
private $model;
/**
* Set the template name
* @param String $template
*/
public function setTemplate($template){
$this->template = $template;
}
/**
* get the template name
* @return String
*/
public function getTemplate(){
return $this->template;
}
/**
* set the model on the view
* @param ModelData $model
*/
public function setModel(ModelData $model){
$this->model = $model;
}
/**
* allow the template to get
* variable from the model
* @param String key
* @return Any
*/
public function get($key){
return $model->get($key);
}
/**
* magic diplay method
*/
public function __toString(){
$this->display();
}
/**
* display the view
*/
private function display(){
$config = Configuration::getInstance();
$template = $config->get('APP_ROOT').'/view/templates/html/' . $this->getTemplate() . '.php';
if(!file_exists($template)){
throw new TemplateNotFoundException('Template name : ' .$template);
}
include_once($template);
}
}
?>
the include
<?php
$filename = $this->get('image_path');
header('Content-type: image/'.$this->get('image_format'));
header('Content-length: '.filesize($filename));
readfile($filename);
?>