Commit initial
This commit is contained in:
49
server/webplatform/apps/CameraMonitor/Framework/View.php
Normal file
49
server/webplatform/apps/CameraMonitor/Framework/View.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
require_once $GLOBALS['app_path'].'Framework/Configuration.php';
|
||||
|
||||
class View {
|
||||
|
||||
private $file;
|
||||
|
||||
public function __construct($action, $controller = "") {
|
||||
$file = $GLOBALS['app_path']."View/";
|
||||
if ($controller != "") {
|
||||
$file = $file . $controller . "/";
|
||||
}
|
||||
$this->file = $file . $action . ".php";
|
||||
}
|
||||
|
||||
public function generate($data) {
|
||||
$content = $this->generateFile($this->file, $data);
|
||||
|
||||
$title = "";
|
||||
$headScript = "";
|
||||
if(isset($data['title']))
|
||||
$title = $data['title'];
|
||||
if(isset($data['headScript']))
|
||||
$headScript = $data['headScript'];
|
||||
|
||||
$root = Configuration::get("root", "/");
|
||||
$vue = $this->generateFile($GLOBALS['app_path'].'View/template.php',
|
||||
array('headScript'=> $headScript, 'title' => $title, 'content' => $content,
|
||||
'root' => $root));
|
||||
echo $vue;
|
||||
}
|
||||
|
||||
private function generateFile($file, $data) {
|
||||
if (file_exists($file)) {
|
||||
extract($data);
|
||||
ob_start();
|
||||
require $file;
|
||||
return ob_get_clean();
|
||||
}
|
||||
else {
|
||||
throw new Exception("Fichier '$file' introuvable");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private function clean($value) {
|
||||
return htmlspecialchars($value, ENT_QUOTES, 'UTF-8', false);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user