I have this script as my index.php
<?php
include_once "templates/header.php";
include_once "templates/website/navi1.php";
define("PAGE_DIR", dirname(__FILE__) . "/templates/website");
require_once "templates/FrontController.php";
FrontController::createInstance()->dispatch();
include_once "templates/footer.php";
?>
And I have this as my frontcontroller:
<?php
class FrontController {
public static function createInstance() {
if (!defined("PAGE_DIR")) {
exit("Critical error: Cannot proceed without PAGE_DIR.");
}
$instance = new self();
return $instance;
}
public function dispatch() {
$page = !empty($_GET["page"]) ? $_GET["page"] : "main";
$class = ucfirst($page) . "page";
//e.g. pages/home/HomeActions.php
$file = PAGE_DIR . "/" . $page . ".php";
if (!is_file($file)) {
exit("Page not found");
}
require_once $file;
}
}
?>
Both of these I had gotten off the internet and it does work however its pretty limited I need to go into sub folders and such but I'm stuck as how to go about this a link or tutorial would be nice or just some pointers.
Thanks,