- added error_reporting if devMode

- added TestController.php
- added temp function to load controllers (should load later via seo urls)
- added baseTemplate for default look and feel
- removed adding file extension -> always need to be .php!
This commit is contained in:
VersusTune 2020-04-03 13:19:26 +02:00
commit 7ba4e3e0a6
8 changed files with 97 additions and 14 deletions

View file

@ -12,6 +12,7 @@ class VenomRenderer
private Venom $venom;
private ?RenderController $controller;
private string $templateData = '';
private array $vars = [];
private string $baseTemplate = '';
private string $templateDir = '';
private string $assetsDir = '';
@ -25,8 +26,8 @@ class VenomRenderer
{
if ($this->controller) {
ob_start();
$this->controller->render();
$this->templateData = ob_end_clean();
$this->controller->render($this);
$this->templateData = ob_get_clean();
}
$this->loadBasicTemplate();
}
@ -36,16 +37,45 @@ class VenomRenderer
if (file_exists($this->templateDir . $this->baseTemplate)) {
include_once $this->templateDir . $this->baseTemplate;
} else {
echo "Base Template not found...";
echo $this->templateData;
echo 'Base Template not found...';
}
}
/**
* function will load a template (without extension!) into a variable and return the content
* @param $template
* @param string $varName
* @return false|string
*/
public function includeTemplate($template, $varName = '')
{
$template .= '.php';
if (file_exists($this->templateDir . $template)) {
ob_start();
include_once $this->templateDir . $template;
$data = ob_get_clean();
$this->vars[$varName] = $data;
return $data;
}
$this->vars[$varName] = '';
return '';
}
public function addVar($name, $value)
{
$this->vars[$name] = $value;
}
public function getVar($name)
{
return $this->vars[$name];
}
public function init(?RenderController $controller): void
{
$this->controller = $controller;
$data = Config::getInstance()->getRenderer();
$this->baseTemplate = $data['baseFile'] ?? 'base.php';
$this->baseTemplate = $data['baseFile'] . '.php' ?? 'base.php';
$this->templateDir = __DIR__ . '/../../../tpl/' . $data['theme'] . '/';
$this->assetsDir = __DIR__ . '/../../../public/theme/' . $data['theme'] . '/';
}