Source Rally PHP Community Scripts .. Sign up .. Login
In most sites each page is in a different file. I will show you how to organize your code so only the differing parts of your web page require a new file. In most cases you will initialize all the same scripts for each page. The ones that don’t need certain scripts initialized we wont worry about. The degrade in performance doesn’t effect the user too much.
Access: Public      Tags: PHP, Templates, Applications, HTML
Add to favourites       Subscribe comments       Copy code       Bookmark
In most sites each page is in a different file. I will show you how to organize your code so only the differing parts of your web page require a new file. In most cases you will initialize all the same scripts for each page. The ones that don’t need certain scripts initialized we wont worry about. The degrade in performance doesn’t effect the user too much.

First we start off with a simple script in our index.php file which will handle applications and loading templates.

    <?php
    $app 
$_GET[app]?$_GET[app]:’home’;
    include(
"templates/main.php");
    
?> 

In the above code $_GET[app] is checked, if it is not set it defaults to home. Then templates/main.php is included this will be your template file with little php in it. The following is an example template.

    <html>
        <head>
            <title>My Site</title>
        </head>
        <body>
            <div id="wrapper">
                <div id="header" />
                <div id="content">
                    <?php include("apps/".$app.".php"?>
                </div>
                <div id="footer" />
            </div>
        </body>
    </html>

This file should be in the templates directory. It is a simple div template with minimal PHP. The PHP loads the app file that was set by index.php. Most editing to this template can be done with CSS. To complete the system we need one more file. The following is the contents of home.php.

    <h1>Main Page</h1> 

Place this file in the apps directory. For the main page you simply put http://www.yoursite.com/ into your browser link bar. To access alternative applications http://www.yoursite.com/?app=appname excluding the .php of the file name because it is hard coded into the template. index.php was omitted from the app link because it’s not needed the real link would appear as http://www.yoursite.com/index.php?app=appname

This method could use some error checking, but is the one of the most simple methods of doing application handling and template loading.
Add to favourites       Subscribe comments       Copy code       Bookmark
Sign up to add your own comment here!

Shared by:

nexuslite

Mail user Add to friends
All user contributed content is available under the LGPL unless specified otherwise.
Remaining copyrights Regin Gaarsmand © 2006-2008
About SourceRally.net
Adelgazar sin trucos Programador PHP