Forum Moderators: coopster & phranque

Message Too Old, No Replies

Site architecture, directory structure

Building a dynamic website

         

mipapage

12:00 pm on May 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Scenario
Okay, I'm currently in the throws of building my first two dynamic websites. I am at ground zero with PHP, hacking together something that will work 'cause I have to finish these sites for tomorrow.

More technical info: I am using (example) template.php with an include that contains functions. The include looks like this:

include("{$page}.php"); That gets the content, the varible is checked before being passed, if it fails it goes to error.php. The urls are rewritten with mod_rewrite to appear 'clean'.

Now, I'm used to designing static sites. Usually, if warranted, I will bury a section 'down a directory' if I feel that I need the organization. Now, with these PHP sites, I am having trouble getting my head around how to do this - or if I even need to. I can think of some ways to do it, but I want to know the 'right' ways.

I have searched here and on Google, but I am not sure that I even know what the topic I am searching for is called:

Is there a link to, or can someone explain the thoughts behind directory srtructure/strategy for dynamic websites?
It's messing with my mind


Disclaimer: Any missing of the obvious or 'd'oh, why didn't I realize that?' type of stuff is attributed to too many days awake and over-the-limit caffeine levels - oh, and cause I'm a PHP newbie.

Birdman

1:10 pm on May 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello, the best way to keep it organized is to use a database to store the content of the website. You can create a table for main sections(main menu) of the site, sub-sections(if needed), and then a table for the actual products or articles(or whatever your page info is).

phpMyAdmin [phpmyadmin.sourceforge.net] is a great web-based utility to use if your host has it installed.

Here is a basic example of a database structure:

Table sections
sec-id TINYINT(2) NOT NULL AUTO-INCREMENT
sec-name VARCHAR(150) NOT NULL
sec-description TEXT NOT NULL //(main body)
sec-head TEXT NOT NULL //(for <title> and <meta> info)
PRIMARY KEY(sec-id)

Table sub-sections
sub-id TINYINT(2) NOT NULL AUTO-INCREMENT
sub-sec-id TINYINT(2) NOT NULL //(referrence to sections)
sub-name VARCHAR(150) NOT NULL
sub-description TEXT NOT NULL //(main body)
sub-head TEXT NOT NULL //(for <title> and <meta> info)
PRIMARY KEY(sub-id) INDEX(sub-sec-id)

Table products
prod-id VARCHAR(20) NOT NULL //(I use the item # here)
prod-sub-id TINYINT(2) NOT NULL (referrence to sub-sections)
prod-name VARCHAR(150) NOT NULL
prod-description TEXT NOT NULL
prod-cost FLOAT(3,2) NOT NULL
prod-stock[b] TINYINT(3) NOT NULL
PRIMARY KEY(prod-id) INDEX(prod-sub-id)

Now you can extract the page you want by using the variable(s) sent in the url. When I build the urls with mod-rewrite, I use an identifier word like this:

yoursite.com/Green-Widget[b]_Section/
yoursite.com/Green-Widget_Section/Furry-Green-Widget-Sub
yoursite.com/Green-Widget_Section/Furry-Green-Widget-Sub/Show-FGW001.php

I actually build three templates. One for main section views, one for sub-section views and one for product views.

  • section.php
  • sub.php
  • prod.php

.htaccess
RewriteEngine on
RewriteRule ^(.*)-Section/$ /section.php?section=$1
RewriteRule ^(.*)-Section/(.*)-Sub/$ /sub.php?section=$1&sub=$2
RewriteRule ^(.*)-Section/(.*)-Sub/Show-(.*)\.php$ /prod.php?section=$1&sub=$2&prod=$3 [L]

section.php SQL
$sql = "SELECT * FROM sections WHERE sec-id = $section";

section.php SQL
$sql = "SELECT * FROM sub-sections WHERE sec-id = $section AND sub-id = $sub";

section.php SQL
$sql = "SELECT * FROM products WHERE prod-id = $prod";

Keep in mind that there are many ways to set it up, just keep it as simple and logical as you can.

Slade

1:27 pm on May 18, 2003 (gmt 0)

10+ Year Member



As I posted before, I've been building code recently based on the fusebox( [fusebox.org...] ) model.

My links appear on the page as site.com/dir1/item, but I have them rewritten to site.com/index.php?action=dir1.item

With fusebox, you parse for the period, giving you a directory identifier of "dir1", and a content id of "item". Those are generally enough to point you out to the content you actually want to show.

edit: linkified...

Birdman

1:37 pm on May 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The reason I use a a unique word in the url is to keep mod_rewrite from rewriting all urls because I also have static pages. It can be a single character if you want, just something to tell apache what urls I want rewritten.

Like I said, many different approaches.

mipapage

1:37 pm on May 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Birdman,

This is the second or third bit of really really good advice I've gotten from you. A huge thank you for taking the time to answer, and at that on the weekend ;-]



I actually build three templates. One for main section views, one for sub-section views and one for product views.
  • section.php[/li]
  • sub.php[/li]
  • prod.php[/li]

I was wondering about this. If I want to move anything down a directory, I need to use another template, don't I? That is what I was thinking, but I thought maybe there was some apache/php trickery that I was unaware of (well, that's a given!)

the best way to keep it organized is to use a database to store the content of the website

I will be looking into this, however, given that I have to finish by tomorrow, it will have to be later next week. The client needs to show someone something close to being finished. They don't need to know that I'll rework the back-end after the fact - but I'll probably tell'em anyway.

Slade, thanks to you too for coming up to bat for me > 1 time! Wrt Fusebox, I'll head over there later this week too.

You've both quelled a couple of my concerns, so thanks again.