Design of a Website

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
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Design of a Website

Post by nigma »

I'd like to get some input from some of the guys on this forum regarding how they would run the backend of a website like mine.

The main things i'm interested in are:
  1. How would you interact with a database?
    Would you write a database abstraction layer, hard-code everything for a particular database, or something else?
  2. How would each page be generated?
    Meaning how would the end result come to be? Would you include the page the user wants based on some variable in the url (i.e. index.php?page=xxx), use a templating engine, or something else?
  3. Anything else you think is worth mentioning.
Thanks for any input.
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

Since it's just your site and not for different people to use, just code a couple of easy-to-use database functions for yourself.

I'd generate each page via ?page=name, but use mod_rewrite so the pages are displayed as /name or /page/name.
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

I understand what you're saying Skara, but even though it is just a personal website it'd be good practice to treat it as if it weren't.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

OK first off.. I should just mention that maybe I'm too drunk to be answering posts :P

1. I'd usually write a class to exclusively handle the database stuff. Depending upon how I'm feeling I'll write something quite generic (which takes more time when you actually come to use it in terms of making calls to functions) or something that's pretty specific for the particular project your working on (convenient once coded).
2. I almost always use ?page=something and have recently started playing with mod_rewrite as Skara says. It's just so clean, tidy and efficient to include things into templates rather than have completely new pages for each URL.
3. Not sure... let me think while I drink :P
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Generally on my sites I have an index which calls my navigation class.
I find this more beneficial than calling pages directly because I can now easily control things like custom errors, user's permissions, etc. I would also recommend using some sort of templating engine to seperate most of your logic from your html, of course this is much easier to maintain that entangling the two. If your looking for simple template creations, I would probably create your own templating class which isn't difficult at all. Not bashing Smarty but I find it to be overkill at times.

Generally I have a library class that I use over and over on every site. Things like such

1) Database Abstraction Layer
2) Navigation layer
3) User control layer
4) Templating layer

and so on. I'm sure that you've noticed certain patterns emerge when creating sites, atleast I know I have. 95% of the sites I do are CMS, so all of the mentioned can be re-used. Your own site is a perfect place to start developing these things.
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

Alright, thanks for the input.

Jcart, do you pull your navigation links from a database? I've been thinking about doing something like this so that I could add/delete pages from the web. Also, for your DBA do you use a factory class? It'd be nice if you could do something like:

Code: Select all

$dbi = new Database;
and then have Database return a database specific object based on the value of a variable in the Database class. Maybe you can ?
dreamline
Forum Contributor
Posts: 158
Joined: Fri May 28, 2004 2:37 am

Post by dreamline »

Well i think programming is something personal, every programmer has it's own choices, for one i rather use 1 page as a tree for all the other pages. And as for a connection to a db, i hardcode every query and try to avoid putting the whole site into a database itself.. hehehe.. j/k..

I still have to start on OOP but sofar my sites are working, but there's always room for improvement.

But to answer your questions: I think it's a personal choice of how you code it and what you wanna do with a db.. But make sure you feel good about how you do it.. :)
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

currently my <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span> (uh-oh, accidentally typo :p) has:

- sql generation class
- resultset2xml function
- xslt function

- each page has it's own physical page/script.

- the administration section uses the same code.. and i have some standard files to generate a "(paginated) list, add, delete, edit, search" page..
Post Reply