Mark Cunningham
January 6th, 2009, 07:32 PM
I have been using a structure for my PHP apps that has a central controller that all http requests go through.
<?php
include('db_fnc.php');
db_connection();
$controller="home";
$view=empty($_GET[view]) ? "index" : $_GET[view];
if($_POST[tutorial_submit])
{
insert_tutorial();
}
switch($view)
{
case"index";
$tutorials=db_select_all_rows(tutorials);
$ar=array("introduction","instalation","first_script","html_php","variables");
if(!isset($_GET[next_pos]) && !isset($_GET[previous_pos]))
{
$next_po_include="introduction";
}
elseif(isset($_GET[next_pos]))
{
$next_po_include=$_GET[next_pos];
}
elseif(isset($_GET[previous_pos]))
{
$next_po_include=$_GET[previous_pos];
}
///////////LOOP THAT CREATES THE NEXT PREVIOUS LINKS///////////
for($count=0;$ar[$count];$count++)
{
if($next_po_include==$ar[$count])
{
$next=$ar[($count+1)];
$previous=$ar[$count-1];
}
}
break;
/////////////
case"contact_us";
$controller="contact_us";
break;
/////////////
case"tutorial_feed";
$controller="tutorial_feed";
break;
/////////////
case"edit";
$controller="edit";
break;
/////////////
case"individual_tutorial";
$tutorial=db_select_one_rows(tutorials);
$controller="individual_tutorial";
break;
/////////////
case"adding_tutorial";
$controller="adding_tutorial";
break;
/////////////
case"forum";
$controller="forum";
break;
/////////////
case"replies";
$controller="replies";
break;
/////////////
}
//include($_SERVER['DOCUMENT_ROOT']."/view/layouts/".$layout."/".$view.".php");
include($_SERVER['DOCUMENT_ROOT'].'/views/layouts/'.$controller.'.php');
?>
a bit messy but it allows for a strict directory structure for my files so I can separate my HTML from PHP.
Well my question is what structures are others using is there a better one like MVC which I think is a bit overkill but still an improvement.
<?php
include('db_fnc.php');
db_connection();
$controller="home";
$view=empty($_GET[view]) ? "index" : $_GET[view];
if($_POST[tutorial_submit])
{
insert_tutorial();
}
switch($view)
{
case"index";
$tutorials=db_select_all_rows(tutorials);
$ar=array("introduction","instalation","first_script","html_php","variables");
if(!isset($_GET[next_pos]) && !isset($_GET[previous_pos]))
{
$next_po_include="introduction";
}
elseif(isset($_GET[next_pos]))
{
$next_po_include=$_GET[next_pos];
}
elseif(isset($_GET[previous_pos]))
{
$next_po_include=$_GET[previous_pos];
}
///////////LOOP THAT CREATES THE NEXT PREVIOUS LINKS///////////
for($count=0;$ar[$count];$count++)
{
if($next_po_include==$ar[$count])
{
$next=$ar[($count+1)];
$previous=$ar[$count-1];
}
}
break;
/////////////
case"contact_us";
$controller="contact_us";
break;
/////////////
case"tutorial_feed";
$controller="tutorial_feed";
break;
/////////////
case"edit";
$controller="edit";
break;
/////////////
case"individual_tutorial";
$tutorial=db_select_one_rows(tutorials);
$controller="individual_tutorial";
break;
/////////////
case"adding_tutorial";
$controller="adding_tutorial";
break;
/////////////
case"forum";
$controller="forum";
break;
/////////////
case"replies";
$controller="replies";
break;
/////////////
}
//include($_SERVER['DOCUMENT_ROOT']."/view/layouts/".$layout."/".$view.".php");
include($_SERVER['DOCUMENT_ROOT'].'/views/layouts/'.$controller.'.php');
?>
a bit messy but it allows for a strict directory structure for my files so I can separate my HTML from PHP.
Well my question is what structures are others using is there a better one like MVC which I think is a bit overkill but still an improvement.