2020-05-15 12:27:34 +02:00

49 lines
1.4 KiB
PHP

<?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);
}
}