diff --git a/config.base.php b/config.base.php index a4baae4..28e5c98 100644 --- a/config.base.php +++ b/config.base.php @@ -40,7 +40,7 @@ $config->setMail([ // all themes are in __DIR__/public/theme/ $config->setRender([ 'theme' => 'default', //very important! it will search for a folder with this name. - 'baseFile' => 'base.php', //this will called after all templates are rendered... + 'baseFile' => 'base', //this will called after all templates are rendered... 'useCache' => false, //is only on big systems good 'cacheName' => 'defaultCache', //this is for bigger systems, ignore it ]); diff --git a/module.base.php b/module.base.php index c1a1ca6..aacea87 100644 --- a/module.base.php +++ b/module.base.php @@ -4,4 +4,6 @@ $modules = []; // register controllers that can handle templates ;) need to have a render function for this -$controllers = []; \ No newline at end of file +$controllers = [ + 'test' => \Modules\TestController::class +]; \ No newline at end of file diff --git a/public/index.php b/public/index.php index 1cc9a02..d20bbb8 100755 --- a/public/index.php +++ b/public/index.php @@ -22,6 +22,11 @@ if ($config->isMaintenance()) { echo 'Currently not available'; exit; } +//if devMode is on show all errors! +if ($config->isDevMode()) { + error_reporting(E_ALL); + ini_set('error_reporting', E_ALL); +} $venom = new Venom(); $venom->initModules($modules); $venom->initControllers($controllers); diff --git a/src/Venom/Venom.php b/src/Venom/Venom.php index 1382879..6cd02b5 100644 --- a/src/Venom/Venom.php +++ b/src/Venom/Venom.php @@ -22,10 +22,18 @@ class Venom { // we need to load the current controller and the current start template. // after this we can start the renderer - $this->renderer->init(null); + $this->renderer->init($this->findController()); $this->renderer->render(); } + private function findController(): ?RenderController + { + if (isset($_GET['cl'], $this->controllers[$_GET['cl']])) { + return $this->controllers[$_GET['cl']]; + } + return null; + } + public function initModules(array $modules): void { foreach ($modules as $key => $moduleClass) { @@ -50,9 +58,4 @@ class Venom { } - - private function findController() - { - - } } \ No newline at end of file diff --git a/src/Venom/Views/RenderController.php b/src/Venom/Views/RenderController.php index cb724f8..b97c8f8 100644 --- a/src/Venom/Views/RenderController.php +++ b/src/Venom/Views/RenderController.php @@ -8,7 +8,7 @@ interface RenderController { public function register(): bool; - public function render(): string; + public function render(VenomRenderer $renderer): bool; public function getTemplate(): string; } \ No newline at end of file diff --git a/src/Venom/Views/VenomRenderer.php b/src/Venom/Views/VenomRenderer.php index f8b9ffa..6b08b60 100644 --- a/src/Venom/Views/VenomRenderer.php +++ b/src/Venom/Views/VenomRenderer.php @@ -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'] . '/'; } diff --git a/src/modules/TestController.php b/src/modules/TestController.php new file mode 100644 index 0000000..839a4a2 --- /dev/null +++ b/src/modules/TestController.php @@ -0,0 +1,27 @@ + + + + + + + VenomBase + + +
+ VenomCMS +
+templateData ?> + + \ No newline at end of file