Database allowed empty, twig grabs global vars

This commit is contained in:
2025-03-03 12:23:02 -08:00
parent f76bbfb27c
commit d183c4c1e0
4 changed files with 21 additions and 6 deletions

View File

@@ -18,8 +18,10 @@ require_once(FRAMEWORKPATH . '/src/Session.php');
$session = new Session();
// Load Database Class
require_once(FRAMEWORKPATH . '/src/Database.php');
$db = new Database($config['database']);
if (!empty($config['database']['host'])) {
require_once(FRAMEWORKPATH . '/src/Database.php');
$db = new Database($config['database']);
}
// Load a controller
require_once(FRAMEWORKPATH . '/src/Router.php');

View File

@@ -1,14 +1,21 @@
<?php
//Twig
function view($name = '', $data = [] ) {
function view($name = '', $data = []) {
global $config; // Use the globally included $config
$loader = new Twig\Loader\FilesystemLoader(BASEPATH . '/App/views/');
$loader->addPath(BASEPATH . '/vendor/4lt/novaconium/twig', 'novaconium');
$loader->addPath(BASEPATH . '/App/templates', 'override');
$twig = new Twig\Environment($loader);
//check if file exists
$twig = new Twig\Environment($loader);
// Add config to Twig globally
$twig->addGlobal('config', $config);
// Check if the template exists
if (file_exists(BASEPATH . '/App/views/' . $name . '.html.twig')) {
echo $twig->render("$name" . '.html.twig', $data);
echo $twig->render("$name.html.twig", $data);
return true;
} else {
echo "Error: Twig Template ($name) Not Found.";