Jump to content

How can I do this?


Kryllster

Recommended Posts

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,

Link to comment
https://forums.phpfreaks.com/topic/259467-how-can-i-do-this/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.