Organising my PHP scripts
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Organising my PHP scripts

Threaded View

  1. #1
    Join Date
    Jan 2009
    Location
    UK
    Posts
    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 06: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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center