SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast fLUx1337's Avatar
    Join Date
    Jul 2007
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arrow Whats the best practice to layout/structure a web app?

    Hey,

    I'm currently designing a web app, but I cant work out how to lay it out, so it all works...

    (not the design layout, I mean how the header, content, footer & sidebar gets put together, plus the mod_rewrite nice urls...)

    This is how I currently have it laid out:

    home.php
    Code:
    include header.php //inc all info on stylesheets, etc..
    
    $page_name = strtolower($_GET['page']);
    $page_name = trim($page_name, " ");
    
    if $page == 'blah' {
    include blah.php
    }elseif $page == 'foo'{
    include foo.php
    }elseif $page == 'bar'{
    include bar.php
    }....etc....
    
    include footer.php // inc </div> for site wrapper, and inc sidebar
    (I know the above isnt full valid php, its just quick to show you....hehe)

    .htaccess
    Code:
    RewriteEngine on
    RewriteRule ^blah$ home.php?page=blah
    RewriteRule ^foo$ home.php?page=foo
    RewriteRule ^bar$ home.php?page=bar
    And I end up with something like this:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w93.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/199/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="css/style.css" rel="stylesheet" type="text/css" />
    <title>Site - Blah</title>
    </head>
    <body>
    
    <div id="wrapper">
    <div id="head">head</div>
    
    <div id='content'>Blah Page</div>
    
    <div id='sidebar'>blah</div>
    <div id="foot">foot</div>
    
    </div>
    
    </body>
    </html>
    BUT, I'm coming across problems, like not being able to use header(); in the content files, because data has already been sent to the browser from the header file.....and simple problems like that....if you've ever designed a site from scratch, I think you will know what I mean....

    So, if you design sites which have dynamic pages, and you use nice urls using mod_rewrite, please post a detailed (if possible) description about how you do it, to a) make it as easy as possible to add pages & b) cause as little disruption to your current, or future php code....

    Thanks alot in advance!

    fLUx

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    How I do it? I use the MVC approach having the three layers strictly separated. The View layer is the Composite View -- the main template with different page parts inserted. For the Controller layer I use Chain of Responsibility, usually I have one dispatcher command that connects the ends of all commands and forms the response. Solves the said problems and then some.

    Look up the terms in italic for more insight. All of that actually has been discussed on the advanced php forums, you can start there.
    Saul

  3. #3
    SitePoint Enthusiast fLUx1337's Avatar
    Join Date
    Jul 2007
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh OK, so according to wikipedia, a MVC is a framework, yeh?

    Are frameworks really worth the time it takes to learn them? I've looked into CakePHP before, but didn't really understand why it would be useful...

    Lets say I wanted to (re)create ****.com (I don't, but its a pretty basic layout for most sites to use as an example), would I benefit from a framework?

    As I don't know what sites are based on frameworks like CakePHP, I don't really know what they can achieve....

    Any help would be great.....because my current project has come to a complete and utter stop!

    Cheers!

    fLUx

  4. #4
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Oh no, MVC is just a concept that basically says that the application can be seen as an aggregate of three different layers -- model, view and controller. All serve their purpose and should be separate and interact between each other.

    I think most popular frameworks, including CakePHP, are based on this concept. You might really check into one of them, it would make your life ten times easier. I can't recommend any particular because I work on my own for several reasons; but check out these forums, there were several threads on which framework to choose.
    Saul

  5. #5
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    MVC is a framework in the sense that it is a conceptual model of how to organize your code. It's not a framework like CakePHP, it's merely an organizational model. MVC imposes no limits on what you can do - your limitations are solely those of the language you are using.
    PHP questions? RTFM
    MySQL questions? RTFM


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •