Layout for building a PHP web page/site...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
B-truE
Forum Newbie
Posts: 2
Joined: Thu May 08, 2003 9:03 pm

Layout for building a PHP web page/site...

Post by B-truE »

I'd like to create some organized web pages using HTML & PHP.

I want to have include files that will be used on the various pages (e.g. header.inc, footer.inc, styles.css, sidenav.inc ...).

I want to know how to put it all together, so that it builds uniformly, up to standards, and works correctly.

How do I construct the body (index.php) page (tables...) to hold these includes? If the body is a table with fields setup to hold the includes, is it ok to have tables in the include files? In other words, if my header.inc contains a multicell table, is it ok to include that into a table field in the body (index.php) - table in table? Or, what is the best way to set this all up?

An example of each element (index.php, header.inc, sidebar.inc...) would be helpful.

Also, what tool do you like best for constructing styles?

Thanks...

B-truE
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

hm, not exactly what you've asked for but did you consider using something like postNuke or typo3 ?
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Nested tables work fine - but many web designers have moved on to style positioning attributes for page layout. I'm not totally convinced about that but google around for more info and make up your own mind. It gets tricky only if you want to support older browsers.

An stylesheet atatched to a bunch of html templates is one way to control styles.

It's hard to give you an example of how to combine evrything together but basically I think you're looking for a chain of includes to draw each page. Try experimenting with a "php nav plan" to work out how to do it all with the minimum number of includes (more efficient). What I mean by that is do a kind of flow chart to show which file needs to include which other files.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Use require() or include(). Just substitute the included file in place of the code you have in the external file.

Here is a basic example:

Code: Select all

<html>
<head>
<title>Max's Page</title>
</head>
<body bgcolor="#33ccff">
 <table border="1" valign="center">
  <tr>
    <td><? require("./header.inc"); ?></td>
  </tr>
  <tr>
    <td><? require("./body.php"); ?></td>
  </tr>
  <tr>
    <td><? require("./footer.inc"); ?></td>
  </tr>
 </table>
</body>
</html>
B-truE
Forum Newbie
Posts: 2
Joined: Thu May 08, 2003 9:03 pm

header.inc...

Post by B-truE »

I'd like to see an example of the header.inc/footer.inc/body.inc files. I'm concerened about how the tables in those files cooperate with the table in the main index.php file.

Thanks.

B-truE
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Here's how I'm building a CMS with lots of different functions (forum, articles, claendar etc) as separate "modules".

All pages are included in a single index.php file in the site root. This file processes GET vars and includes a modules/module_name/index.php file which goes something like this:

Code: Select all

<?php
$page_title="Articles";

echo $meta;

// starts html code; all html between <head> tags
echo $head;                    

// header layout element (a table)
include("html/header_dynamic.htm"); 

// the page body (single row table)
echo $opentable_mainbody; // fn which starts a table

boxColumn("l"); // sidebar placed in the left table cell

echo $spacer_cell;

// open table cell for main body content
echo '<td align ="left" valign="top">';

// main functions file which will switch case to draw lists, view single items, add items etc
include('modules/articles/main.php');

// close table cell
echo '</td>';

// close table
echo $closetable_mainbody;

// footer layout element (a table)
include("html/footer.htm"); 
?>
There's a table for the header, a single row table for the sidebar & main page content (placed in separate cells) and a table for the footer.

This may or not be the best way to do it, but it works for me.

As I mentioned previously, many people use style positioning rather than tables. I don't in part because I want to allow people to easily change page layouts without having any CSS skills.

Incidentally, including everything in a single index.php file (not the module index.php the one in the site root) provides a handy "gateway" to do things like authentication or include common scripts (eg a db connection script).
Post Reply