Organising my PHP scripts
I have been using a structure for my PHP apps that has a central controller that all http requests go through.
PHP Code:
<?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.
Re: Organising my PHP scripts
There are any number of paradigms to follow when developing a large web application. The beauty of MVC is that it allows a separation of concerns. The controller and any helper objects are the responsibility of the server-side framework teams. The models are responsibility of the server-side application guys. The views are the responsibility of graphic designers and client side coders.
If you're dealing with a small-scale application, then yes, it might be a bit of overkill, but it is still easier to keep your source nice and neat by using MVC.
Cocoa, Swing and Flex are all pretty stellar.