Database allowed empty, twig grabs global vars
This commit is contained in:
parent
f76bbfb27c
commit
d183c4c1e0
@ -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
3
docs/twig-overrides.md
Normal file
@ -0,0 +1,3 @@
|
||||
# Twig Overrides
|
||||
|
||||
You can override twig templates by creating the same file in the templates directory.
|
@ -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');
|
||||
|
15
src/twig.php
15
src/twig.php
@ -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.";
|
||||
|
Loading…
x
Reference in New Issue
Block a user