-
January 6th, 2009, 08:32 PM
#1
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.
Last edited by PeejAvery; January 7th, 2009 at 07:38 AM.
Reason: Added PHP tags.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|