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

Hybrid 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 07:38 AM. Reason: Added PHP tags.

  2. #2
    Join Date
    Aug 2005
    Location
    Milwaukee, WI
    Posts
    55

    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.
    Meddle not in the affairs of dragons, human, for thou art crunchy and taste good with ketchup.

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