92 lines
1.5 KiB
PHP
92 lines
1.5 KiB
PHP
<?php
|
|
/**
|
|
* Created by CS medien- & kommunikationssysteme.
|
|
* @author Christian Steinle
|
|
* @date 03.08.2016
|
|
*
|
|
* @copyright CS medien- & kommunikationssysteme (http://www.steinle-computer.de)
|
|
*/
|
|
|
|
namespace View;
|
|
|
|
use \Helper\Registry;
|
|
|
|
|
|
class StandardView
|
|
{
|
|
/**
|
|
* Pfad zur Template Datei
|
|
* @var string
|
|
*/
|
|
protected $template = '';
|
|
|
|
/**
|
|
* Das Daten-Array, das in die Inhaltsbereiche des Templates gerendert wird
|
|
* @var array
|
|
*/
|
|
protected $data = array();
|
|
|
|
/**
|
|
* Ist der Inhalt bearbeitbar
|
|
* @var bool
|
|
*/
|
|
protected $isEditable = false;
|
|
|
|
|
|
/**
|
|
* StandardView constructor.
|
|
* Setzt den Pfad zum Template und die Daten
|
|
*
|
|
* @param array $data
|
|
* @param $template
|
|
*/
|
|
public function __construct(array $data, $template)
|
|
{
|
|
$this->setTemplate($template);
|
|
$this->data = $data;
|
|
}
|
|
|
|
|
|
/**
|
|
* @param $isEditable
|
|
*/
|
|
public function setEditable($isEditable)
|
|
{
|
|
$this->isEditable = $isEditable;
|
|
}
|
|
|
|
|
|
/**
|
|
* Setzt den Pfad zum Template
|
|
*
|
|
* @param $template
|
|
* @throws \Exception
|
|
*/
|
|
private function setTemplate($template)
|
|
{
|
|
$templateFile = PATH_TPL . mb_strtolower($template) . '.phtml';
|
|
if (!file_exists($templateFile))
|
|
{
|
|
throw new \Exception('Template file "' . $templateFile . '" does not exist!');
|
|
}
|
|
$this->template = $templateFile;
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* Gibt das befüllte Template als HTML zurück
|
|
*
|
|
* @return string
|
|
*/
|
|
public function render()
|
|
{
|
|
ob_start();
|
|
include($this->template);
|
|
|
|
$templateContent = ob_get_contents();
|
|
ob_end_clean();
|
|
|
|
return $templateContent;
|
|
}
|
|
} |