Page 1 of 1

Design of a Website

Posted: Fri Jun 17, 2005 6:15 pm
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.

Posted: Fri Jun 17, 2005 6:26 pm
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.

Posted: Fri Jun 17, 2005 6:30 pm
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.

Posted: Fri Jun 17, 2005 6:39 pm
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

Posted: Fri Jun 17, 2005 6:39 pm
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.

Posted: Fri Jun 17, 2005 9:05 pm
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 ?

Posted: Sat Jun 18, 2005 10:13 am
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.. :)

Posted: Sat Jun 18, 2005 11:18 am
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..