Help with php and file organizing

software development

#1

Ok what Im trying to do is approach this another way to make it more organized for me and others instead of having all my coded files together.

My index.php file (has my layout images and everything inside)

<?php if (isset($_GET['page'])) { include("{$_SERVER['DOCUMENT_ROOT']}/includes/{$_GET['page']}.php"); } else { include("{$_SERVER['DOCUMENT_ROOT']}/includes/staff.php"); } ?>

I use this code to grab my php files. Well let’s say since Im doing gaming on my site also. I have devilmaycry4.php which is in my includes folder. Well instead I want to put it another folder called xbox360. I think I just confused myself now. lol sorry. Just wanted to see if you guys had a idea to help me make it more organized. Need anymore info I’ll be around.

Matta


#2

include("{$_SERVER[‘DOCUMENT_ROOT’]}/xbox360/devilmaycry4.php");


#3

The way I’ve solved this problem in the past is to use some type of name -> page mapping that I either store in a PHP associative array or, if I think I might need fancier information, inside a database. Given what you’re trying to do, a PHP associative array is probably your best solution. You could rewrite index.php to look like this:

[code]<?php
$page_include = Array(
‘staff’ => ‘includes/staff.php’,
‘devilmaycry4’ => ‘xbox360/devilmaycry4.php’
/* and so forth */
);

$page = isset($page_includes[$_GET[‘page’]]) ? $page_includes[$_GET[‘page’]] : $page_includes[‘staff’];

include("{$_SERVER[‘DOCUMENT_ROOT’]}/$page");
?>
[/code]