Kryllster Posted March 22, 2012 Share Posted March 22, 2012 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, Quote Link to comment https://forums.phpfreaks.com/topic/259467-how-can-i-do-this/ Share on other sites More sharing options...
scootstah Posted March 22, 2012 Share Posted March 22, 2012 What needs to go into sub folders? Quote Link to comment https://forums.phpfreaks.com/topic/259467-how-can-i-do-this/#findComment-1330165 Share on other sites More sharing options...
Kryllster Posted March 23, 2012 Author Share Posted March 23, 2012 I believe it would be the PAGE_DIR which as it is only allows for 1 set directory I Have several of these as controllers in this project but I want to use just 1 controller instead of several. Does that help?? Quote Link to comment https://forums.phpfreaks.com/topic/259467-how-can-i-do-this/#findComment-1330366 Share on other sites More sharing options...
scootstah Posted March 23, 2012 Share Posted March 23, 2012 Does that help?? Not really. :/ Can you give me an example with pseudo code or something? I'm still not sure what you're trying to do. Quote Link to comment https://forums.phpfreaks.com/topic/259467-how-can-i-do-this/#findComment-1330467 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.