PHP Site Structure

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
cjconnor24
Forum Newbie
Posts: 13
Joined: Wed Oct 29, 2008 6:31 am

PHP Site Structure

Post by cjconnor24 »

Please excuse me if this is the wrong category (this is my first post on here).

I have just started getting into PHP and have bought a few books to learn about creating database driven websites. However, i can't seem to find out the best way to structure the actual folders on my server when using includes.

Could anyone offer any advice?

I've noticed on a few sites people appear to use a folder for each page (or at least this is what it looks like to my untrained eye):

http://www.thewebsite.com/about/
http://www.thewebsite.com/products/
http://www.thewesite.com/contact/

you get the idea, im sure.

Any help would be much appreciated and i hope, once i learn a bit more, to be able to contribute to this forum :D

Thanks,
C
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Re: PHP Site Structure

Post by panic! »

They are probably using Model View Controller.

Where each of those urls probably doesn't relate to a real folder on the file system, but relates to a model name (which is probably the name of a table on the database).

So the url

http://www.site.com/product/edit/1

is

model/action/id

or maybe

http://www.site.com/product/view/ball-point-pens

is

model/action/parameter

all of these will be passed into index.php (probably) and it will work out how and which things to display.

the Model View Controller pattern might be a bit complex for a total beginner but if you can get to grips with it then great! :)
cjconnor24
Forum Newbie
Posts: 13
Joined: Wed Oct 29, 2008 6:31 am

Re: PHP Site Structure

Post by cjconnor24 »

wow, yeh i think that probably is a bit out of my reach at the moment!!! :(

Could anyone then recommend the best course for me to take when structuring my site?

Thanks, again, in advance :D
C
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Re: PHP Site Structure

Post by panic! »

I'd say to begin with, if it's a small project, do how feels best to you...but learn from your mistakes...you will make many.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: PHP Site Structure

Post by josh »

You will probably find rewrite rules of some interest
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: PHP Site Structure

Post by Eran »

Those are most likely just url beautification and not actual folders. This can be achieved using two methods: url rewriting at the server level (apache has mod_rewrite) or parsing at the script level (here is a nice tutorial for url beautification in PHP).
EPX
Forum Newbie
Posts: 19
Joined: Fri Nov 21, 2008 3:22 am
Location: Stafford, UK

Re: PHP Site Structure

Post by EPX »

It all depends on the type of site your make, or should i say the size.

If you have a small site (up to 50 pages) that you want people to find on google, try and keep all the files in the root with excetion to images, css, pdf's and other such files which should be in sub folders. Google doesn't like drilling to far down sub folders.

if you have a bigger site, it's difficult to manage sites using just the root directory. so i would only recommend only going up to 2 sub directories deep.

Try and keep directory stuctures simple.
Post Reply