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.
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.
.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.
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...
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]
the best way to keep it organized is to use a database to store the content of the website