Database allowed empty, twig grabs global vars

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

View File

@ -16,7 +16,10 @@ Master Repo: https://git.4lt.ca/4lt/novaconium
```bash
mkdir project_name;
cd project_name;
# Native
composer require 4lt/novaconium
# Composer
docker run --rm --interactive --tty --volume $PWD:/app composer require 4lt/novaconium
cp -R vendor/4lt/novaconium/defaults/App/ .
cp -R vendor/4lt/novaconium/defaults/public/ .
```

3
docs/twig-overrides.md Normal file
View File

@ -0,0 +1,3 @@
# Twig Overrides
You can override twig templates by creating the same file in the templates directory.

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.";