diff --git a/src/Router.php b/src/Router.php index 6bde1a7..98ae2fb 100644 --- a/src/Router.php +++ b/src/Router.php @@ -34,7 +34,12 @@ class Router { private function setRouteFile() { foreach ($this->routes as $key => $value) { if ( $this->path == $key) { - $this->controllerPath = BASEPATH . '/App/controllers/' . $value['file'] . '.php'; + $theFile = BASEPATH . '/App/controllers/' . $value['file'] . '.php'; + + //check if the file exists + if (file_exists($theFile)) { + $this->controllerPath = $theFile; + } break; } } diff --git a/src/novaconium.php b/src/novaconium.php index 021711c..d79524d 100644 --- a/src/novaconium.php +++ b/src/novaconium.php @@ -2,12 +2,22 @@ require_once(BASEPATH . '/vendor/autoload.php'); //Twig -$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); +function view($name = '', $data = [] ) { + $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 + if (file_exists(BASEPATH . '/App/views/' . $name . '.html.twig')) { + echo $twig->render("$name" . '.html.twig', $data); + return true; + } else { + echo "Error: Twig Template ($name) Not Found."; + return false; + } +} // Load a controller require_once('Router.php'); $router = new Router(); -require_once($router->controllerPath); \ No newline at end of file +require_once($router->controllerPath); diff --git a/twig/master.html.twig b/twig/master.html.twig index fd5c21b..144e94a 100644 --- a/twig/master.html.twig +++ b/twig/master.html.twig @@ -8,45 +8,45 @@ + + {# Page Header #} +
+ {% block headerbefore %}{% endblock %} + {% include ['@override/nav.html.twig', '@novaconium/nav.html.twig'] %} + {% block headerafter %}{% endblock %} +
- {# Page Header #} -
- {% block headerbefore %}{% endblock %} - {% include ['@override/nav.html.twig', '@novaconium/nav.html.twig'] %} - {% block headerafter %}{% endblock %} -
+ +
+
- -
-
+
+ {% if error|default is not empty %} + {% for key, val in error %} +
{{ val }}
+ {% endfor %} + {% endif %} -
- {% if error|default is not empty %} - {% for key, val in error %} -
{{ val }}
- {% endfor %} - {% endif %} + {% if notice|default is not empty %} + {% for key, val in notice %} +
{{ val }}
+ {% endfor %} + {% endif %} - {% if notice|default is not empty %} - {% for key, val in notice %} -
{{ val }}
- {% endfor %} - {% endif %} +
+ {% block content %}{% endblock %} +
+
-
- {% block content %}{% endblock %} -
-
-
- - {# Page Footer #} -
- {% block footerbefore %}{% endblock %} - {% include ['@override/footer.html.twig', '@novaconium/footer.html.twig'] %} - {% block footerafter %}{% endblock %} -
+ {# Page Footer #} + + {% include ['@override/foot.html.twig', '@novaconium/foot.html.twig'] %}