Jump to content

How to implement a front controller.


Kryllster

Recommended Posts

First I want to give my page controller code to show where Im at with it today.

<?php
session_start();
$username = $_SESSION['username'];

// db config
include ('includes/db_config.php');

// Select data from database
$sql = "SELECT * FROM $tbl_name WHERE username='$username'";
$result = mysql_query($sql);

// Put info into array Hopefully
while($row = mysql_fetch_assoc($result))
{

// player config
include('includes/player_config.php');

// all pages array
include 'includes/pagesArray.php';

// start gui for entire game
include('header_view.php');
include('player_view.php');

// nightslyr code for page request
if (!in_array($_GET['show'], $accepted)) //$accepted is the array of all accepted page names
{
   echo "That page does not exist";
}
else
{
// navigation pages for the town
   if($_GET['show'] == "account" || $_GET['show'] == "alley_man" || $_GET['show'] == "alley_view" || $_GET['show'] == "archer" || $_GET['show'] == "armor" || $_GET['show'] == "bank" || $_GET['show'] == "chat" || $_GET['show'] == "cloth" || $_GET['show'] == "crimson" || $_GET['show'] == "garden" || $_GET['show'] == "inn" || $_GET['show'] == "mage" || $_GET['show'] == "main" || $_GET['show'] == "merchant" || $_GET['show'] == "weapons" || $_GET['show'] == "recovery_room")
   {
      require_once("dungeons/town/" . $_GET['show'] . ".php");
   }

// navigation pages for dungeon1
  if($_GET['show'] == "failure" || $_GET['show'] == "fight_success" || $_GET['show'] == "fight_success2" || $_GET['show'] == "fight_success3" || $_GET['show'] == "guard_view" || $_GET['show'] == "hallway" || $_GET['show'] == "hallway2" || $_GET['show'] == "hallway3" || $_GET['show'] == "hallway4" || $_GET['show'] == "hallway5" || $_GET['show'] == "low_guards2" || $_GET['show'] == "low_guards3" || $_GET['show'] == "main1" || $_GET['show'] == "room1a" || $_GET['show'] == "room1b" || $_GET['show'] == "room2" || $_GET['show'] == "room2a" || $_GET['show'] == "room2b" || $_GET['show'] == "room3b" || $_GET['show'] == "room4b" || $_GET['show'] == "treasure_failure" || $_GET['show'] == "treasure_failure2" || $_GET['show'] == "treasure_failure3" || $_GET['show'] == "treasure_failure4" || $_GET['show'] == "treasure_success" || $_GET['show'] == "treasure_success2" || $_GET['show'] == "treasure_success3" || $_GET['show'] == "treasure_success4")
  {
    require_once("dungeons/dungeon1/" . $_GET['show'] . ".php");
  }

// navigation pages for dungeon2
  if($_GET['show'] == "d2_shop" || $_GET['show'] == "d2buy_skills" || $_GET['show'] == "d2fight_failure" || $_GET['show'] == "d2fight_success" || $_GET['show'] == "droom1" || $_GET['show'] == "droom1a" || $_GET['show'] == "droom1b" || $_GET['show'] == "droom1c" || $_GET['show'] == "droom1d" || $_GET['show'] == "droom1e" || $_GET['show'] == "droom1f" || $_GET['show'] == "droom2" || $_GET['show'] == "droom2a" || $_GET['show'] == "droom2b" || $_GET['show'] == "droom2c" || $_GET['show'] == "droom2d" || $_GET['show'] == "droom2e" || $_GET['show'] == "droom2f" || $_GET['show'] == "droom2g" || $_GET['show'] == "droom2h" || $_GET['show'] == "droom2i" || $_GET['show'] == "droom2j" || $_GET['show'] == "droom2k" || $_GET['show'] == "droom2l" || $_GET['show'] == "droom3" || $_GET['show'] == "droom3a" || $_GET['show'] == "droom3b" || $_GET['show'] == "droom3c" || $_GET['show'] == "droom3d" || $_GET['show'] == "droom3e" || $_GET['show'] == "droom3f" || $_GET['show'] == "entrance" || $_GET['show'] == "failure_cubby" || $_GET['show'] == "failure_treasure" || $_GET['show'] == "main2" || $_GET['show'] == "shopkeeper" || $_GET['show'] == "success_cubby" || $_GET['show'] == "success_special" || $_GET['show'] == "success_treasure")
  {
    require_once("dungeons/dungeon2/" . $_GET['show'] . ".php");
  }

// navigation pages for dungeon3
  if($_GET['show'] == "d3fight1" || $_GET['show'] == "d3fight2" || $_GET['show'] == "d3fight3" || $_GET['show'] == "d3fight4" || $_GET['show'] == "d3fight5" || $_GET['show'] == "d3main" || $_GET['show'] == "groom1" || $_GET['show'] == "groom1a" || $_GET['show'] == "groom2" || $_GET['show'] == "groom2a" || $_GET['show'] == "groom3" || $_GET['show'] == "groom3a" || $_GET['show'] == "groom4" || $_GET['show'] == "groom4a" || $_GET['show'] == "groom5" || $_GET['show'] == "groom5a" || $_GET['show'] == "groomfinish")
  {
    require_once("dungeons/dungeon3/" . $_GET['show'] . ".php");
  }

// navigation pages for dungeon 4
  if($_GET['show'] == "d4entrance" || $_GET['show'] == "d4fightsuccess" || $_GET['show'] == "d4room1" || $_GET['show'] == "d4room2" || $_GET['show'] == "d4room3" || $_GET['show'] == "d4room4" || $_GET['show'] == "d4fight1_loot" || $_GET['show'] == "d4room5" || $_GET['show'] == "d4room6" || $_GET['show'] == "d4room7" || $_GET['show'] == "d4room8" || $_GET['show'] == "d4room9" || $_GET['show'] == "d4room10" || $_GET['show'] == "d4room11" || $_GET['show'] == "d4room12" || $_GET['show'] == "d4room13" || $_GET['show'] == "d4room14" || $_GET['show'] == "d4room15" || $_GET['show'] == "d4room16" || $_GET['show'] == "d4room17" || $_GET['show'] == "d4room18" || $_GET['show'] == "d4room19" || $_GET['show'] == "d4room20" || $_GET['show'] == "d4room21" || $_GET['show'] == "d4room22" || $_GET['show'] == "d4room23" || $_GET['show'] == "d4fight1" || $_GET['show'] == "d4fight2" || $_GET['show'] == "d4fight2_loot" || $_GET['show'] == "d4fight3" || $_GET['show'] == "d4fight3_loot" || $_GET['show'] == "d4fight4" || $_GET['show'] == "d4fight4_loot" || $_GET['show'] == "d4fight5" || $_GET['show'] == "d4fight5_loot")
  {
    require_once("dungeons/dungeon4/" . $_GET['show'] . ".php");
  }

// navigation pages for dungeon 5
if($_GET['show'] == "d5entrance" || $_GET['show'] == "d5room1" || $_GET['show'] == "d5room2" || $_GET['show'] == "d5room3" || $_GET['show'] == "d5room4" || $_GET['show'] == "d5room5" || $_GET['show'] == "d5room6" || $_GET['show'] == "d5room7" || $_GET['show'] == "d5room8" || $_GET['show'] == "d5room9" || $_GET['show'] == "d5room10" || $_GET['show'] == "d5room11" || $_GET['show'] == "d5room12" || $_GET['show'] == "d5room13" || $_GET['show'] == "d5room14" || $_GET['show'] == "d5room15" || $_GET['show'] == "d5fight1" || $_GET['show'] == "d5fight1_loot" || $_GET['show'] == "d5fight2" || $_GET['show'] == "d5fight2_loot" || $_GET['show'] == "d5fight3" || $_GET['show'] == "d5fight3_loot")
{
    require_once("dungeons/dungeon5/" . $_GET['show'] . ".php");
    }

// miscellaneous pages in the files folder
if($_GET['show'] == "armor_requirements" || $_GET['show'] == "bow_requirements" || $_GET['show'] == "congratulations" || $_GET['show'] == "d4fight_failure" || $_GET['show'] == "fight1_loot" || $_GET['show'] == "fight_failure" || $_GET['show'] == "fight_failure4" || $_GET['show'] == "fightfailure1" || $_GET['show'] == "gallery" || $_GET['show'] == "help" || $_GET['show'] == "requirements" || $_GET['show'] == "staff_requirements" || $_GET['show'] == "warn_enemy" || $_GET['show'] == "warn_gems" || $_GET['show'] == "warn_money" || $_GET['show'] == "warn_rations" || $_GET['show'] == "warn_special" || $_GET['show'] == "warn_treasure" || $_GET['show'] == "warnenemy" || $_GET['show'] == "character_info")
  {
    require_once("dungeons/files/" . $_GET['show'] . ".php");
  }

// do not edit below here for now Sep 10, 2009
}
include('footer_view.php');
}
?>

 

What I want to be able to do is drop a folder or files into the stucture of the website making it easily extensable. I was told by another member that a frontcontroller would benefit my game real well. All that Im able to find as far as info seems more cryptic. Something simple but adaptable where do I go for something easy???

Link to comment
https://forums.phpfreaks.com/topic/199230-how-to-implement-a-front-controller/
Share on other sites

Well I want to be able to read the folders and files in certain directories and using that info call the pages sent to the controller file. I have some code that doesnt work but will kind of show what I think needs to be done.

 

<?php

$pages = $_GET['show'];
$open = opendir("files/");
$read = readdir($open);
$accepted = array($read);
	if(in_array($read, $accepted) == $pages($_GET['show'])){
		require_once($pages . ".php");
	}
	else{
		echo "That Page Does Not Exist!";
	}
closedir($open); 
?>

 

Im still looking as I know this is probably not the way to do this but Im trying to figure it out.

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.